Arduino-cli showing error: panic: runtime error: invalid memory address or nil pointer dereference

Hi,
I have been starting using arduino-cli (using the bash terminal in visual studio code), and compiled and uploaded several old sketches without any issues. Then I tried to compile sketches with 3rd party libraries and updated my .yaml file for that.
After trying to compile one sketch with a library that was not found I just get this error (does not matter which command or sketch i tried to use):


$ arduino-cli update
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x0 pc=0x54bb22]

goroutine 1 [running]:
github.com/arduino/go-paths-helper.(*Path).Join(0x0, 0xc0004db6d8, 0x1, 0x1, 0x0)
        /github/home/go/pkg/mod/github.com/arduino/go-paths-helper@v1.3.2/paths.go:83 +0x52
github.com/arduino/arduino-cli/configuration.HardwareDirectories(0xc00003a891, 0x22, 0x7)
        /__w/arduino-cli/arduino-cli/configuration/directories.go:44 +0x18f
github.com/arduino/arduino-cli/arduino/cores/packagemanager.(*PackageManager).LoadHardware(0xc0002f2080, 0xc0003e6700, 0x0)
        /__w/arduino-cli/arduino-cli/arduino/cores/packagemanager/loader.go:33 +0x2d
github.com/arduino/arduino-cli/commands.createInstance(0x10781a0, 0xc0000340d0, 0xdffe00, 0xc0002f4001, 0xc0002e60d0, 0xc000269988)
        /__w/arduino-cli/arduino-cli/commands/instances.go:635 +0x893
github.com/arduino/arduino-cli/commands.Init(0x10781a0, 0xc0000340d0, 0xc0004dbad8, 0xc0002f4040, 0xc0002e60d0, 0x400, 0x203000000000000, 0x50)
        /__w/arduino-cli/arduino-cli/commands/instances.go:134 +0x5c
github.com/arduino/arduino-cli/cli/instance.getInitResponse(0xc0002f8000, 0x50, 0x48)
        /__w/arduino-cli/arduino-cli/cli/instance/instance.go:47 +0xd1
github.com/arduino/arduino-cli/cli/instance.CreateInstanceIgnorePlatformIndexErrors(...)
        /__w/arduino-cli/arduino-cli/cli/instance/instance.go:31
github.com/arduino/arduino-cli/cli/update.runUpdateCommand(0xc0002a4000, 0x17244e8, 0x0, 0x0)
        /__w/arduino-cli/arduino-cli/cli/update/update.go:52 +0x3e
github.com/spf13/cobra.(*Command).execute(0xc0002a4000, 0x17244e8, 0x0, 0x0, 0xc0002a4000, 0x17244e8)
        /github/home/go/pkg/mod/github.com/spf13/cobra@v1.0.1-0.20200710201246-675ae5f5a98c/command.go:846 +0x2b1
github.com/spf13/cobra.(*Command).ExecuteC(0xc0001badc0, 0x0, 0xd6b0a0, 0xc00003c0b8)
        /github/home/go/pkg/mod/github.com/spf13/cobra@v1.0.1-0.20200710201246-675ae5f5a98c/command.go:950 +0x350
github.com/spf13/cobra.(*Command).Execute(...)
        /github/home/go/pkg/mod/github.com/spf13/cobra@v1.0.1-0.20200710201246-675ae5f5a98c/command.go:887
main.main()
        /__w/arduino-cli/arduino-cli/main.go:31 +0x3d

i know there are questions with the same error, but those were caused by a particular sketch, I repeat myself maybe, but right now i cannot run any command on arduino-cli (not even arduino-cli update)

I have a windows 10 laptop and arduino 1.8.15 installed. My arduino IDE is fine and it works normally, the problem i am facing is with the arduino-cli.

is there any way to refresh the arduino-cli? I dont think I have to reinstall the arduino IDE.

Thank you very much in advance.

here my arduino-cli.yaml

board_manager:
  additional_urls:
  - https://raw.githubusercontent.com/VSChina/azureiotdevkit_tools/master/package_azureboard_index.json
  - http://arduino.esp8266.com/stable/package_esp8266com_index.json
  - https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json
  - https://adafruit.github.io/arduino-board-index/package_adafruit_index.json
  - https://dl.espressif.com/dl/package_esp32_index.json
  - https://mcudude.github.io/MicroCore/package_MCUdude_MicroCore_index.json
  - https://raw.githubusercontent.com/sleemanj/optiboot/master/dists/package_gogo_diy_attiny_index.json
daemon:
  port: "50051"
directories:
  data: C:\Users\ocamp\AppData\Local\Arduino15
  downloads: C:\Users\ocamp\AppData\Local\Arduino15\staging
  user:
  - C:\Users\ocamp\OneDrive\Documents\Arduino
  - C:\Users\ocamp\Documents\IoTanks\Repo_2021\libraries
logging:
  file: ""
  format: text
  level: info
telemetry:
  addr: :9090
  enabled: true

i already downloaded the arduino-cli and copied the executable and license under the same directory and still the same issue, i also stripped down the .yaml without all the additional urls :upside_down_face: and the problem is consistent. No matter what i put in the command line, i get the same error

Hi @iotanks76. Which version of Arduino CLI are you using?

1 Like

$ arduino-cli version
arduino-cli.exe alpha Version: 0.18.3 Commit: d710b642 Date: 2021-05-14T12:36:58Z

the problem started when I tried to install user libraries with arduino-cli install...

here my c_cpp_properties.json (i dont know if that helps, havent changed it)

{
    "version": 4,
    "configurations": [
        {
            "name": "Arduino",
            "compilerPath": "C:\\Users\\ocamp\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7\\bin\\avr-g++",
            "compilerArgs": [
                "-w",
                "-std=gnu++11",
                "-fpermissive",
                "-fno-exceptions",
                "-ffunction-sections",
                "-fdata-sections",
                "-fno-threadsafe-statics",
                "-Wno-error=narrowing"
            ],
            "intelliSenseMode": "gcc-x64",
            "includePath": [
                "C:\\Users\\ocamp\\Documents\\IoTanks\\arduino-1.8.15\\hardware\\arduino\\avr\\cores\\arduino",
                "C:\\Users\\ocamp\\Documents\\IoTanks\\arduino-1.8.15\\hardware\\arduino\\avr\\variants\\eightanaloginputs",
                "c:\\users\\ocamp\\appdata\\local\\arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7\\lib\\gcc\\avr\\7.3.0\\include",
                "c:\\users\\ocamp\\appdata\\local\\arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7\\lib\\gcc\\avr\\7.3.0\\include-fixed",
                "c:\\users\\ocamp\\appdata\\local\\arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7\\avr\\include"
            ],
            "forcedInclude": [
                "C:\\Users\\ocamp\\Documents\\IoTanks\\arduino-1.8.15\\hardware\\arduino\\avr\\cores\\arduino\\Arduino.h"
            ],
            "cStandard": "c11",
            "cppStandard": "c++11",
            "defines": [
                "F_CPU=16000000L",
                "ARDUINO=10815",
                "ARDUINO_AVR_NANO",

it is even weider, i erased my cli, installed an older version (0.18.1 ) in another directory
and still the same error...
my arduino IDE 1.8.15 works fine....
and I muss confess, I have another version installed (1.8.5) but in another folder and the cli is not in that version (this is my settings,json)

    "arduino.path": "C:\\Users\\ocamp\\Documents\\IoTanks\\arduino-1.8.15",
    "arduino.commandPath": "cli\\arduino-cli.exe",
    "arduino.logLevel": "info",
    "arduino.allowPDEFiletype": false,
    "arduino.enableUSBDetection": true,
    "arduino.disableTestingOpen": false,
    "arduino.skipHeaderProvider": false,
    "arduino.additionalUrls": [
        "http://arduino.esp8266.com/stable/package_esp8266com_index.json"
    ],
    "arduino.defaultBaudRate": 115200
}

Aha! I see the problem now:

This is not supported. You can only have a single user directory. So pick one. For example:

  user: C:\Users\ocamp\OneDrive\Documents\Arduino

I got distracted by an unrelated issue with that "VSChina" Boards Manager URL:

So you'll also need to remove that URL from your configuration. If you really need it, there is a patched version from the PR submitted to fix their syntax error here:
https://raw.githubusercontent.com/VSChina/azureiotdevkit_tools/c3a1ba7990178457326d5033fcad7df1a3bf7d7d/package_azureboard_index.json

thank you very much for the feedback. I removed the additional paths and I still get the error, I reinstalled the cli and removed my previous configuration and still not able to use anything else than the help. I will deinstall the cli and try some time later

Are you getting the exact same panic as before?

Or is there a different error message now?

It's possible that you had multiple unrelated problems stacked up. That presents a confusing situation where fixing one problem only gets you to the next one. That was sort of what happened to me. I immediately ran into that "invalid number literal, trying to unmarshal ""3788484 "" into Number" error when I started trying to reproduce your problem, but then couldn't understand why you were getting a completely different error from it. It took me a little while to notice that there was an additional problem with your configuration.