Skip to content

Don't panic on firmware list without Internet connection #127

Closed
@per1234

Description

@per1234

Describe the current behavior

Running the arduino-fwuploader firmware list command while your computer does not have access to the Internet results in a user unfriendly stack trace.

To Reproduce

  1. Disconnect your computer from the Internet.
  2. Run the arduino-fwuploader firmware list command.
$ arduino-fwuploader version
arduino-fwuploader Version: test-c061e884578ceb9ffcc643a6ec545e1c3fc2b344-git-snapshot Commit: c061e88 Date: 2022-01-14T10:17:26Z

$ arduino-fwuploader firmware list
downloading index https://downloads.arduino.cc/arduino-fwuploader/boards/module_firmware_index.json.gz: Get "https://downloads.arduino.cc/arduino-fwuploader/boards/module_firmware_index.json.gz": dial tcp: lookup downloads.arduino.cc: no such host
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x0 pc=0xa59430]

goroutine 1 [running]:
github.com/arduino/arduino-fwuploader/cli/firmware.list({0x0, 0x0})
        /home/runner/work/arduino-fwuploader/arduino-fwuploader/cli/firmware/list.go:65 +0x90
github.com/arduino/arduino-fwuploader/cli/firmware.newListCommand.func1(0xc0001b6c80, {0xf93458, 0x0, 0x0})
        /home/runner/work/arduino-fwuploader/arduino-fwuploader/cli/firmware/list.go:41 +0x27
github.com/spf13/cobra.(*Command).execute(0xc0001b6c80, {0xf93458, 0x0, 0x0})
        /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.1.3/command.go:856 +0x5f8
github.com/spf13/cobra.(*Command).ExecuteC(0xc0001b6000)
        /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.1.3/command.go:960 +0x3ad
github.com/spf13/cobra.(*Command).Execute(...)
        /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.1.3/command.go:897
main.main()
        /home/runner/work/arduino-fwuploader/arduino-fwuploader/main.go:34 +0x45

Describe the request

Print an error message that clearly communicates the problem to the user:

The output of the other commands under these conditions is fine:

$ arduino-fwuploader.exe firmware flash -b arduino:samd:nano33iot -a COM36 -m NINA
Can't load package index: downloading index https://downloads.arduino.cc/packages/package_index.json.gz: Get "https://downloads.arduino.cc/packages/package_index.json.gz": dial tcp: lookup downloads.arduino.cc: no such host

IMO, panics should only be used in cases that should never occur. When such a thing does occur, a developer must investigate and the stack trace will be very useful for that. But the tool running without access to the Internet is a normal condition, and so should be handled gracefully.

Environment

  • Updater version: test-c061e884578ceb9ffcc643a6ec545e1c3fc2b344-git-snapshot Commit: c061e88 Date: 2022-01-14T10:17:26Z
  • OS and platform: Windows 10

Additional context

Real world example of this causing some alarming looking Arduino IDE 2.x startup output, which acted as a "red herring":
https://forum.arduino.cc/t/arduino-2-0-not-starting-up/950998/5

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions