Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash in upload if the upload tool platform is missing #2211

Merged
merged 2 commits into from
Jun 13, 2023

Conversation

cmaglie
Copy link
Member

@cmaglie cmaglie commented Jun 12, 2023

Please check if the PR fulfills these requirements

See how to contribute

  • The PR has no duplicates (please search among the Pull Requests
    before creating one)
  • The PR follows
    our contributing guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • UPGRADING.md has been updated with a migration guide (for breaking changes)
  • configuration.schema.json updated if new parameters are added.

What kind of change does this PR introduce?

Fix a crash in upload if:

  • The platform requires an upload tool from another (referenced) platform
  • The referenced platform is missing

What is the current behavior?

See #2042 for more details:

$ arduino-cli compile -b arduino:avr:uno --upload arduino-cli/internal/integrationtest/testdata/bare_minimum
Sketch uses 444 bytes (1%) of program storage space. Maximum is 32256 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x30 pc=0xaee351]

goroutine 1 [running]:
github.com/arduino/arduino-cli/arduino/cores/packagemanager.(*Explorer).GetInstalledPlatformRelease(0xc00076f600, 0xc0003ba9c0?)
        /home/megabug/Workspace/arduino-cli/arduino/cores/packagemanager/package_manager.go:576 +0x31
github.com/arduino/arduino-cli/commands/upload.runProgramAction(0xc00076f600, 0xc000721ce2?, {0x0, 0x0}, {0x0, 0x0}, {0x7ffcf7a16ea4, 0xf}, 0x40f5e8?, {0x0, ...}, ...)
        /home/megabug/Workspace/arduino-cli/commands/upload/upload.go:276 +0x97e
github.com/arduino/arduino-cli/commands/upload.Upload({0x17791f0?, 0x0?}, 0xc00029b040, {0x114bd00, 0xc00012b068}, {0x114bd00, 0xc00012b080})
        /home/megabug/Workspace/arduino-cli/commands/upload/upload.go:143 +0x445
github.com/arduino/arduino-cli/internal/cli/compile.runCompileCommand(0xc00038aa00?, {0xc0002599c0, 0x1, 0x4?})
        /home/megabug/Workspace/arduino-cli/internal/cli/compile/compile.go:268 +0x1287
github.com/spf13/cobra.(*Command).execute(0xc00038aa00, {0xc000259980, 0x4, 0x4})
        /home/megabug/Software/go/pkg/mod/github.com/spf13/cobra@v1.2.1/command.go:860 +0x663
github.com/spf13/cobra.(*Command).ExecuteC(0xc0002a9180)
        /home/megabug/Software/go/pkg/mod/github.com/spf13/cobra@v1.2.1/command.go:974 +0x3bd
github.com/spf13/cobra.(*Command).Execute(0x0?)
        /home/megabug/Software/go/pkg/mod/github.com/spf13/cobra@v1.2.1/command.go:902 +0x19
main.main()
        /home/megabug/Workspace/arduino-cli/main.go:31 +0xea

What is the new behavior?

arduino-cli compile -b arduino:avr:uno --upload /home/megabug/Workspace/arduino-cli/internal/integrationtest/testdata/bare_minimum
Sketch uses 444 bytes (1%) of program storage space. Maximum is 32256 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.
Error during Upload: Platform 'foo:avr' not found

Does this PR introduce a breaking change, and is titled accordingly?

No

Other information

Fix #2042

@cmaglie cmaglie self-assigned this Jun 12, 2023
@cmaglie cmaglie added topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project labels Jun 12, 2023
@cmaglie cmaglie added this to the Arduino CLI 0.34.0 milestone Jun 12, 2023
@codecov
Copy link

codecov bot commented Jun 12, 2023

Codecov Report

Patch coverage: 72.72% and project coverage change: +0.12 🎉

Comparison is base (8cd7297) 62.86% compared to head (1b61a3f) 62.98%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2211      +/-   ##
==========================================
+ Coverage   62.86%   62.98%   +0.12%     
==========================================
  Files         218      218              
  Lines       19462    19466       +4     
==========================================
+ Hits        12235    12261      +26     
+ Misses       6145     6122      -23     
- Partials     1082     1083       +1     
Flag Coverage Δ
unit 62.98% <72.72%> (+0.12%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
commands/upload/upload.go 74.68% <72.72%> (+0.21%) ⬆️

... and 1 file with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@cmaglie cmaglie merged commit 422a42c into arduino:master Jun 13, 2023
@cmaglie cmaglie deleted the fix_panic_in_tool_selection branch June 13, 2023 08:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Panic when platform of referenced tool command pattern not installed
3 participants