Skip to content

Improve error code when platform not available for OS #2933

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions commands/cmderrors/cmderrors.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package cmderrors

import (
"errors"
"fmt"
"strings"

Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions commands/service_platform_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package commands

import (
"context"
"errors"
"fmt"

"github.com/arduino/arduino-cli/commands/cmderrors"
Expand Down Expand Up @@ -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}
}

Expand Down
4 changes: 3 additions & 1 deletion internal/arduino/cores/packagemanager/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
}

Expand Down