Skip to content

Commit cf5db1b

Browse files
authored
Fixed weird error message in core install if invalid platform is spcified (#2309)
* Fixed weird error message in 'core install' if invalid platform is specified * Fixed integration test
1 parent 5e01a2e commit cf5db1b

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

Diff for: arduino/errors.go

+2-5
Original file line numberDiff line numberDiff line change
@@ -837,11 +837,8 @@ type MultiplePlatformsError struct {
837837
}
838838

839839
func (e *MultiplePlatformsError) Error() string {
840-
return tr("Found %d platform for reference \"%s\":\n%s",
841-
len(e.Platforms),
842-
e.UserPlatform,
843-
strings.Join(e.Platforms, "\n"),
844-
)
840+
return tr("Found %d platforms matching \"%s\": %s",
841+
len(e.Platforms), e.UserPlatform, strings.Join(e.Platforms, ", "))
845842
}
846843

847844
// ToRPCStatus converts the error into a *status.Status

Diff for: internal/cli/arguments/reference.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,13 @@ func ParseReference(arg string) (*Reference, error) {
116116
}
117117
// replace the returned Reference only if only one occurrence is found,
118118
// otherwise return an error to the user because we don't know on which platform operate
119-
if len(foundPlatforms) == 1 {
120-
ret.PackageName = toks[0]
121-
ret.Architecture = toks[1]
122-
} else {
119+
if len(foundPlatforms) == 0 {
120+
return nil, &arduino.PlatformNotFoundError{Platform: arg}
121+
}
122+
if len(foundPlatforms) > 1 {
123123
return nil, &arduino.MultiplePlatformsError{Platforms: foundPlatforms, UserPlatform: arg}
124124
}
125+
ret.PackageName = toks[0]
126+
ret.Architecture = toks[1]
125127
return ret, nil
126128
}

Diff for: internal/integrationtest/core/core_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,7 @@ func TestCoreDownloadMultiplePlatforms(t *testing.T) {
883883
// The cli should not allow it since optimizing the casing results in finding two cores
884884
_, stderr, err := cli.Run("core", "upgrade", "Packager:Arch")
885885
require.Error(t, err)
886-
require.Contains(t, string(stderr), "Invalid argument passed: Found 2 platform for reference")
886+
require.Contains(t, string(stderr), "Invalid argument passed: Found 2 platforms matching")
887887
}
888888

889889
func TestCoreWithMissingCustomBoardOptionsIsLoaded(t *testing.T) {

0 commit comments

Comments
 (0)