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 1 commit
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
Next Next commit
arduino: improve error code when platform not available for OS
  • Loading branch information
alessio-perugini committed Jun 11, 2025
commit f701abd05a84124feec3b0e5b1c3b7a3717e5762
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
}

// PlatformNotAvaliableForOSError is returned when a platform contains a tool not aviable
// for the user OS + ARCH
type PlatformNotAvaliableForOSError struct {
Platform string
Cause error
}

func (e *PlatformNotAvaliableForOSError) 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 *PlatformNotAvaliableForOSError) GRPCStatus() *status.Status {
return status.New(codes.FailedPrecondition, e.Error())
}

func (e *PlatformNotAvaliableForOSError) 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.PlatformNotAvaliableForOSError{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
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy