Skip to content

Commit

Permalink
Fixed weird error message in core install if invalid platform is sp…
Browse files Browse the repository at this point in the history
…cified (#2309)

* Fixed weird error message in 'core install' if invalid platform is specified

* Fixed integration test
  • Loading branch information
cmaglie committed Sep 11, 2023
1 parent 5e01a2e commit cf5db1b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
7 changes: 2 additions & 5 deletions arduino/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -837,11 +837,8 @@ type MultiplePlatformsError struct {
}

func (e *MultiplePlatformsError) Error() string {
return tr("Found %d platform for reference \"%s\":\n%s",
len(e.Platforms),
e.UserPlatform,
strings.Join(e.Platforms, "\n"),
)
return tr("Found %d platforms matching \"%s\": %s",
len(e.Platforms), e.UserPlatform, strings.Join(e.Platforms, ", "))
}

// ToRPCStatus converts the error into a *status.Status
Expand Down
10 changes: 6 additions & 4 deletions internal/cli/arguments/reference.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,13 @@ func ParseReference(arg string) (*Reference, error) {
}
// replace the returned Reference only if only one occurrence is found,
// otherwise return an error to the user because we don't know on which platform operate
if len(foundPlatforms) == 1 {
ret.PackageName = toks[0]
ret.Architecture = toks[1]
} else {
if len(foundPlatforms) == 0 {
return nil, &arduino.PlatformNotFoundError{Platform: arg}
}
if len(foundPlatforms) > 1 {
return nil, &arduino.MultiplePlatformsError{Platforms: foundPlatforms, UserPlatform: arg}
}
ret.PackageName = toks[0]
ret.Architecture = toks[1]
return ret, nil
}
2 changes: 1 addition & 1 deletion internal/integrationtest/core/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ func TestCoreDownloadMultiplePlatforms(t *testing.T) {
// The cli should not allow it since optimizing the casing results in finding two cores
_, stderr, err := cli.Run("core", "upgrade", "Packager:Arch")
require.Error(t, err)
require.Contains(t, string(stderr), "Invalid argument passed: Found 2 platform for reference")
require.Contains(t, string(stderr), "Invalid argument passed: Found 2 platforms matching")
}

func TestCoreWithMissingCustomBoardOptionsIsLoaded(t *testing.T) {
Expand Down

0 comments on commit cf5db1b

Please sign in to comment.