From dda68ac22f7ac179fc02871ee81eaf4335b936ac Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Fri, 30 Jul 2021 12:20:25 +0200 Subject: [PATCH] Fix error printing when core uninstall fails during upgrade The code tried to log the wrong error, which was nil, hiding the real error. This originally occurred for example when a version of the core was already installed manually in the sketchbook, and you would try to install another version using arduino-cli, though that has since been fixed (arduino-cli no longer tries to uninstall cores from the sketchbook). To still reproduce this problem, you can e.g. break the permissions of an installed core: $ arduino-cli core install arduino:avr@1.8.1 (...) $ chmod a-w ~/.arduino15/packages/arduino/hardware/avr/1.8.1 $ arduino-cli core install arduino:avr@1.8.2 Tool arduino:avr-gcc@7.3.0-atmel3.6.1-arduino5 already installed Tool arduino:avrdude@6.3.0-arduino17 already installed Tool arduino:arduinoOTA@1.3.0 already installed Downloading packages... arduino:avr@1.8.2 already downloaded Upgrading arduino:avr@1.8.1 with arduino:avr@1.8.2... Error upgrading platform: %!s()... Error during install: upgrading platform: removing platform files: unlinkat /home/matthijs/.arduino15/packages/arduino/hardware/avr/1.8.1/firmwares: permission denied With this fix applied, this produces a proper error message: $ arduino-cli core install arduino:avr@1.8.2 Tool arduino:avr-gcc@7.3.0-atmel3.6.1-arduino5 already installed Tool arduino:avrdude@6.3.0-arduino17 already installed Tool arduino:arduinoOTA@1.3.0 already installed Downloading packages... arduino:avr@1.8.2 already downloaded Upgrading arduino:avr@1.8.1 with arduino:avr@1.8.2... Error upgrading platform: removing platform files: unlinkat /home/matthijs/.arduino15/packages/arduino/hardware/avr/1.8.1/firmwares: permission denied... Error during install: upgrading platform: removing platform files: unlinkat /home/matthijs/.arduino15/packages/arduino/hardware/avr/1.8.1/firmwares: permission denied --- commands/core/install.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/core/install.go b/commands/core/install.go index a7040763800..2655614e722 100644 --- a/commands/core/install.go +++ b/commands/core/install.go @@ -145,7 +145,7 @@ func installPlatform(pm *packagemanager.PackageManager, // In case of error try to rollback if errUn != nil { log.WithError(errUn).Error("Error upgrading platform.") - taskCB(&rpc.TaskProgress{Message: fmt.Sprintf(tr("Error upgrading platform: %s"), err)}) + taskCB(&rpc.TaskProgress{Message: fmt.Sprintf(tr("Error upgrading platform: %s"), errUn)}) // Rollback if err := pm.UninstallPlatform(platformRelease); err != nil {