Skip to content

Panic when platform of referenced tool command pattern not installed #2042

Closed
@per1234

Description

@per1234

Describe the problem

Arduino boards platforms can reference resources from other platforms. This introduces a dependency on the referenced platform. Arduino CLI does not support automatic installation of these dependencies along with the dependent platform, so the user must handle the installation, which they don't always do.

If the platform for a referenced tool command pattern is not installed, Arduino CLI panics when running an operation that uses the tool.

🐛 Arduino CLI does not clearly communicate the cause of the error to the user.

To reproduce

$ arduino-cli version
arduino-cli.exe  Version: git-snapshot Commit: a58d5adb Date: 2023-01-23T04:39:11Z

$ export ARDUINO_DIRECTORIES_DATA="/tmp/foo-data" # Use a throwaway directories.data for the demo.

$ arduino-cli core install arduino:[email protected]

[...]

$ echo "uno.upload.tool.default=foo:bar" >> "${ARDUINO_DIRECTORIES_DATA}/packages/arduino/hardware/avr/1.8.6/boards.txt" # Simulate reference of missing platform.

$ arduino-cli sketch new "/tmp/FooSketch"
Sketch created in: C:\Users\per\AppData\Local\Temp\FooSketch

$ arduino-cli compile --fqbn arduino:avr:uno --upload "/tmp/FooSketch"  # Run command that depends on referenced tool.
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 0xc0000005 code=0x0 addr=0x30 pc=0x122ab71]

goroutine 1 [running]:
github.com/arduino/arduino-cli/arduino/cores/packagemanager.(*Explorer).GetInstalledPlatformRelease(0xc005e2fb00, 0xc0003b89c0?)
        E:/git/arduino-cli/arduino/cores/packagemanager/package_manager.go:462 +0x31
github.com/arduino/arduino-cli/commands/upload.runProgramAction(0xc005e2fb00, 0x0?, {0x0, 0x0}, {0x0, 0x0}, {0xc00011e0a0, 0xf}, 0xc000e58f50, {0x0, ...}, ...)
        E:/git/arduino-cli/commands/upload/upload.go:273 +0x91e
github.com/arduino/arduino-cli/commands/upload.Upload({0x1e8b9c0?, 0x0?}, 0xc00046a960, {0x18872e0, 0xc00011d398}, {0x18872e0, 0xc00011d3b0})
        E:/git/arduino-cli/commands/upload/upload.go:143 +0x445
github.com/arduino/arduino-cli/internal/cli/compile.runCompileCommand(0xc00038a280?, {0xc00026bb40, 0x1, 0x4?})
        E:/git/arduino-cli/internal/cli/compile/compile.go:257 +0xedb
github.com/spf13/cobra.(*Command).execute(0xc00038a280, {0xc00026bb00, 0x4, 0x4})
        C:/Users/per/go/pkg/mod/github.com/spf13/[email protected]/command.go:860 +0x663
github.com/spf13/cobra.(*Command).ExecuteC(0xc0002d2a00)
        C:/Users/per/go/pkg/mod/github.com/spf13/[email protected]/command.go:974 +0x3bd
github.com/spf13/cobra.(*Command).Execute(...)
        C:/Users/per/go/pkg/mod/github.com/spf13/[email protected]/command.go:902
main.main()
        E:/git/arduino-cli/main.go:31 +0x77

🐛

Expected behavior

Arduino CLI only panics on unexpected (i.e., caused by a bug in the Arduino CLI codebase) failures. Any failure that can result from normal (even if incorrect) usage should be handled gracefully and the problem clearly communicated to the user.

Arduino CLI version

a58d5ad

Operating system

  • Windows
  • macOS

Operating system version

  • Windows 11
  • macOS Ventura

Additional context

For the sake of simplicity, I simulated the required conditions in the demo by modifying the arduino:avr platform. For a real world occurrence, do an upload using version 0.1.5 of this platform without the sandeepmistry:nRF5 platform installed.


Originally reported by @ljunquera at https://forum.arduino.cc/t/no-connections-established/1048343/19

Issue checklist

  • I searched for previous reports in the issue tracker
  • I verified the problem still occurs when using the nightly build
  • My report contains all necessary details

Metadata

Metadata

Assignees

Labels

topic: codeRelated to content of the project itselftype: imperfectionPerceived defect in any part of project

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions