From d3dbf761ed46428ddc91c521af18a0e31f7b963b Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 12 Jun 2023 17:16:01 +0200 Subject: [PATCH 1/2] Added integration test --- .../integrationtest/upload/upload_test.go | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/internal/integrationtest/upload/upload_test.go b/internal/integrationtest/upload/upload_test.go index dd6a60f3b35..e81bb5e1562 100644 --- a/internal/integrationtest/upload/upload_test.go +++ b/internal/integrationtest/upload/upload_test.go @@ -579,3 +579,27 @@ func TestCompileAndUploadToPortWithBoardAutodetect(t *testing.T) { require.NoError(t, err) } } + +func TestPanicIfUploadToolReferenceAnInexistentPlatform(t *testing.T) { + // See: https://github.com/arduino/arduino-cli/issues/2042 + + env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t) + defer env.CleanUp() + + // Run update-index with our test index + _, _, err := cli.Run("core", "install", "arduino:avr@1.8.5") + require.NoError(t, err) + + // Install test data into datadir + boardsTxt := cli.DataDir().Join("packages", "arduino", "hardware", "avr", "1.8.5", "boards.txt") + boardsTxtData, err := boardsTxt.ReadFile() + require.NoError(t, err) + boardsTxtData = append(boardsTxtData, []byte("uno.upload.tool.default=foo:bar\n")...) + require.NoError(t, boardsTxt.WriteFile(boardsTxtData)) + + sketch, err := paths.New("..", "testdata", "bare_minimum").Abs() + require.NoError(t, err) + + stdout, _, _ := cli.Run("compile", "-b", "arduino:avr:uno", "--upload", sketch.String()) + require.NotContains(t, stdout, []byte("panic:")) +} From 1b61a3fe32507a4717242dda7a0630973c5c5697 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 12 Jun 2023 17:16:19 +0200 Subject: [PATCH 2/2] Fixed panic in upload tool selection --- commands/upload/upload.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/commands/upload/upload.go b/commands/upload/upload.go index 435669af09d..8de4bc009f6 100644 --- a/commands/upload/upload.go +++ b/commands/upload/upload.go @@ -272,13 +272,18 @@ func runProgramAction(pme *packagemanager.Explorer, Property: fmt.Sprintf("%s.tool.%s", action, port.Protocol), // TODO: Can be done better, maybe inline getToolID(...) Value: uploadToolID} } else if len(split) == 2 { + p := pme.FindPlatform(&packagemanager.PlatformReference{ + Package: split[0], + PlatformArchitecture: boardPlatform.Platform.Architecture, + }) + if p == nil { + return &arduino.PlatformNotFoundError{Platform: split[0] + ":" + boardPlatform.Platform.Architecture} + } uploadToolID = split[1] - uploadToolPlatform = pme.GetInstalledPlatformRelease( - pme.FindPlatform(&packagemanager.PlatformReference{ - Package: split[0], - PlatformArchitecture: boardPlatform.Platform.Architecture, - }), - ) + uploadToolPlatform = pme.GetInstalledPlatformRelease(p) + if uploadToolPlatform == nil { + return &arduino.PlatformNotFoundError{Platform: split[0] + ":" + boardPlatform.Platform.Architecture} + } } // Build configuration for upload