From 28a7407194bcf07bba0f46de74dcb42dd65cc652 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 11 Sep 2023 11:47:12 +0200 Subject: [PATCH] Fixed weird error message in 'core install' if invalid platform is specified --- arduino/errors.go | 7 ++----- internal/cli/arguments/reference.go | 10 ++++++---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/arduino/errors.go b/arduino/errors.go index ec60b268ea9..0f30a85dd73 100644 --- a/arduino/errors.go +++ b/arduino/errors.go @@ -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 diff --git a/internal/cli/arguments/reference.go b/internal/cli/arguments/reference.go index 696c963cc2b..a870a0616a2 100644 --- a/internal/cli/arguments/reference.go +++ b/internal/cli/arguments/reference.go @@ -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 }