diff --git a/commands/cmderrors/cmderrors.go b/commands/cmderrors/cmderrors.go index bcc33bc3a8f..38eef33bcc1 100644 --- a/commands/cmderrors/cmderrors.go +++ b/commands/cmderrors/cmderrors.go @@ -16,6 +16,7 @@ package cmderrors import ( + "errors" "fmt" "strings" @@ -415,6 +416,26 @@ func (e *PlatformNotFoundError) Unwrap() error { return e.Cause } +// PlatformNotAvailableForOSError is returned when a platform contains a tool not available +// for the user OS + ARCH +type PlatformNotAvailableForOSError struct { + Platform string + Cause error +} + +func (e *PlatformNotAvailableForOSError) Error() string { + return composeErrorMsg(i18n.Tr("Platform '%s'", e.Platform), errors.New(i18n.Tr("platform is not available for your OS"))) +} + +// GRPCStatus converts the error into a *status.Status +func (e *PlatformNotAvailableForOSError) GRPCStatus() *status.Status { + return status.New(codes.FailedPrecondition, e.Error()) +} + +func (e *PlatformNotAvailableForOSError) Unwrap() error { + return e.Cause +} + // PlatformLoadingError is returned when a platform has fatal errors that prevents loading type PlatformLoadingError struct { Cause error diff --git a/commands/service_platform_install.go b/commands/service_platform_install.go index 9e268339bc8..bd4ea00ddb7 100644 --- a/commands/service_platform_install.go +++ b/commands/service_platform_install.go @@ -17,6 +17,7 @@ package commands import ( "context" + "errors" "fmt" "github.com/arduino/arduino-cli/commands/cmderrors" @@ -79,6 +80,9 @@ func (s *arduinoCoreServerImpl) PlatformInstall(req *rpc.PlatformInstallRequest, } platformRelease, tools, err := pme.FindPlatformReleaseDependencies(ref) if err != nil { + if errors.Is(err, packagemanager.ErrPlatformNotAvailableForOS) { + return &cmderrors.PlatformNotAvailableForOSError{Platform: ref.String()} + } return &cmderrors.PlatformNotFoundError{Platform: ref.String(), Cause: err} } diff --git a/internal/arduino/cores/packagemanager/download.go b/internal/arduino/cores/packagemanager/download.go index 05cc0f70047..d80cd5e9185 100644 --- a/internal/arduino/cores/packagemanager/download.go +++ b/internal/arduino/cores/packagemanager/download.go @@ -26,6 +26,8 @@ import ( semver "go.bug.st/relaxed-semver" ) +var ErrPlatformNotAvailableForOS = errors.New("platform is not available for your OS") + // PlatformReference represents a tuple to identify a Platform type PlatformReference struct { Package string // The package where this Platform belongs to. @@ -89,7 +91,7 @@ func (pme *Explorer) FindPlatformReleaseDependencies(item *PlatformReference) (* } else { release = platform.GetLatestCompatibleRelease() if release == nil { - return nil, nil, errors.New(i18n.Tr("platform is not available for your OS")) + return nil, nil, ErrPlatformNotAvailableForOS } }