Skip to content

Commit f701abd

Browse files
arduino: improve error code when platform not available for OS
1 parent 2947cfb commit f701abd

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

commands/cmderrors/cmderrors.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package cmderrors
1717

1818
import (
19+
"errors"
1920
"fmt"
2021
"strings"
2122

@@ -415,6 +416,26 @@ func (e *PlatformNotFoundError) Unwrap() error {
415416
return e.Cause
416417
}
417418

419+
// PlatformNotAvaliableForOSError is returned when a platform contains a tool not aviable
420+
// for the user OS + ARCH
421+
type PlatformNotAvaliableForOSError struct {
422+
Platform string
423+
Cause error
424+
}
425+
426+
func (e *PlatformNotAvaliableForOSError) Error() string {
427+
return composeErrorMsg(i18n.Tr("Platform '%s'", e.Platform), errors.New(i18n.Tr("platform is not available for your OS")))
428+
}
429+
430+
// GRPCStatus converts the error into a *status.Status
431+
func (e *PlatformNotAvaliableForOSError) GRPCStatus() *status.Status {
432+
return status.New(codes.FailedPrecondition, e.Error())
433+
}
434+
435+
func (e *PlatformNotAvaliableForOSError) Unwrap() error {
436+
return e.Cause
437+
}
438+
418439
// PlatformLoadingError is returned when a platform has fatal errors that prevents loading
419440
type PlatformLoadingError struct {
420441
Cause error

commands/service_platform_install.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package commands
1717

1818
import (
1919
"context"
20+
"errors"
2021
"fmt"
2122

2223
"github.com/arduino/arduino-cli/commands/cmderrors"
@@ -79,6 +80,9 @@ func (s *arduinoCoreServerImpl) PlatformInstall(req *rpc.PlatformInstallRequest,
7980
}
8081
platformRelease, tools, err := pme.FindPlatformReleaseDependencies(ref)
8182
if err != nil {
83+
if errors.Is(err, packagemanager.ErrPlatformNotAvailableForOS) {
84+
return &cmderrors.PlatformNotAvaliableForOSError{Platform: ref.String()}
85+
}
8286
return &cmderrors.PlatformNotFoundError{Platform: ref.String(), Cause: err}
8387
}
8488

internal/arduino/cores/packagemanager/download.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import (
2626
semver "go.bug.st/relaxed-semver"
2727
)
2828

29+
var ErrPlatformNotAvailableForOS = errors.New("platform is not available for your OS")
30+
2931
// PlatformReference represents a tuple to identify a Platform
3032
type PlatformReference struct {
3133
Package string // The package where this Platform belongs to.
@@ -89,7 +91,7 @@ func (pme *Explorer) FindPlatformReleaseDependencies(item *PlatformReference) (*
8991
} else {
9092
release = platform.GetLatestCompatibleRelease()
9193
if release == nil {
92-
return nil, nil, errors.New(i18n.Tr("platform is not available for your OS"))
94+
return nil, nil, ErrPlatformNotAvailableForOS
9395
}
9496
}
9597

0 commit comments

Comments
 (0)