Unverified Commit fb1b9a0a authored by Cristian Maglie's avatar Cristian Maglie Committed by GitHub

[skip-changelog] Return error instead of nil in package/library manager getters (#2476)

It makes explicit that the function may fails to get the package manager
or the library manager.
parent 6732ae0a
...@@ -28,9 +28,9 @@ import ( ...@@ -28,9 +28,9 @@ import (
// Details returns all details for a board including tools and HW identifiers. // Details returns all details for a board including tools and HW identifiers.
// This command basically gather al the information and translates it into the required grpc struct properties // This command basically gather al the information and translates it into the required grpc struct properties
func Details(ctx context.Context, req *rpc.BoardDetailsRequest) (*rpc.BoardDetailsResponse, error) { func Details(ctx context.Context, req *rpc.BoardDetailsRequest) (*rpc.BoardDetailsResponse, error) {
pme, release := instances.GetPackageManagerExplorer(req.GetInstance()) pme, release, err := instances.GetPackageManagerExplorer(req.GetInstance())
if pme == nil { if err != nil {
return nil, &cmderrors.InvalidInstanceError{} return nil, err
} }
defer release() defer release()
......
...@@ -205,9 +205,9 @@ func identify(pme *packagemanager.Explorer, port *discovery.Port) ([]*rpc.BoardL ...@@ -205,9 +205,9 @@ func identify(pme *packagemanager.Explorer, port *discovery.Port) ([]*rpc.BoardL
// In case of errors partial results from discoveries that didn't fail // In case of errors partial results from discoveries that didn't fail
// are returned. // are returned.
func List(req *rpc.BoardListRequest) (r []*rpc.DetectedPort, discoveryStartErrors []error, e error) { func List(req *rpc.BoardListRequest) (r []*rpc.DetectedPort, discoveryStartErrors []error, e error) {
pme, release := instances.GetPackageManagerExplorer(req.GetInstance()) pme, release, err := instances.GetPackageManagerExplorer(req.GetInstance())
if pme == nil { if err != nil {
return nil, nil, &cmderrors.InvalidInstanceError{} return nil, nil, err
} }
defer release() defer release()
...@@ -260,9 +260,9 @@ func hasMatchingBoard(b *rpc.DetectedPort, fqbnFilter *cores.FQBN) bool { ...@@ -260,9 +260,9 @@ func hasMatchingBoard(b *rpc.DetectedPort, fqbnFilter *cores.FQBN) bool {
// Watch returns a channel that receives boards connection and disconnection events. // Watch returns a channel that receives boards connection and disconnection events.
func Watch(ctx context.Context, req *rpc.BoardListWatchRequest) (<-chan *rpc.BoardListWatchResponse, error) { func Watch(ctx context.Context, req *rpc.BoardListWatchRequest) (<-chan *rpc.BoardListWatchResponse, error) {
pme, release := instances.GetPackageManagerExplorer(req.GetInstance()) pme, release, err := instances.GetPackageManagerExplorer(req.GetInstance())
if pme == nil { if err != nil {
return nil, &cmderrors.InvalidInstanceError{} return nil, err
} }
defer release() defer release()
dm := pme.DiscoveryManager() dm := pme.DiscoveryManager()
......
...@@ -21,7 +21,6 @@ import ( ...@@ -21,7 +21,6 @@ import (
"strings" "strings"
"github.com/arduino/arduino-cli/commands" "github.com/arduino/arduino-cli/commands"
"github.com/arduino/arduino-cli/commands/cmderrors"
"github.com/arduino/arduino-cli/commands/internal/instances" "github.com/arduino/arduino-cli/commands/internal/instances"
"github.com/arduino/arduino-cli/internal/arduino/cores" "github.com/arduino/arduino-cli/internal/arduino/cores"
"github.com/arduino/arduino-cli/internal/arduino/utils" "github.com/arduino/arduino-cli/internal/arduino/utils"
...@@ -30,9 +29,9 @@ import ( ...@@ -30,9 +29,9 @@ import (
// ListAll FIXMEDOC // ListAll FIXMEDOC
func ListAll(ctx context.Context, req *rpc.BoardListAllRequest) (*rpc.BoardListAllResponse, error) { func ListAll(ctx context.Context, req *rpc.BoardListAllRequest) (*rpc.BoardListAllResponse, error) {
pme, release := instances.GetPackageManagerExplorer(req.GetInstance()) pme, release, err := instances.GetPackageManagerExplorer(req.GetInstance())
if pme == nil { if err != nil {
return nil, &cmderrors.InvalidInstanceError{} return nil, err
} }
defer release() defer release()
......
...@@ -21,7 +21,6 @@ import ( ...@@ -21,7 +21,6 @@ import (
"strings" "strings"
"github.com/arduino/arduino-cli/commands" "github.com/arduino/arduino-cli/commands"
"github.com/arduino/arduino-cli/commands/cmderrors"
"github.com/arduino/arduino-cli/commands/internal/instances" "github.com/arduino/arduino-cli/commands/internal/instances"
"github.com/arduino/arduino-cli/internal/arduino/utils" "github.com/arduino/arduino-cli/internal/arduino/utils"
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1" rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
...@@ -32,9 +31,9 @@ import ( ...@@ -32,9 +31,9 @@ import (
// installed. Note that platforms that are not installed don't include boards' FQBNs. // installed. Note that platforms that are not installed don't include boards' FQBNs.
// If no search argument is used all boards are returned. // If no search argument is used all boards are returned.
func Search(ctx context.Context, req *rpc.BoardSearchRequest) (*rpc.BoardSearchResponse, error) { func Search(ctx context.Context, req *rpc.BoardSearchRequest) (*rpc.BoardSearchResponse, error) {
pme, release := instances.GetPackageManagerExplorer(req.GetInstance()) pme, release, err := instances.GetPackageManagerExplorer(req.GetInstance())
if pme == nil { if err != nil {
return nil, &cmderrors.InvalidInstanceError{} return nil, err
} }
defer release() defer release()
......
...@@ -57,15 +57,15 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream ...@@ -57,15 +57,15 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
exportBinaries = reqExportBinaries.GetValue() exportBinaries = reqExportBinaries.GetValue()
} }
pme, release := instances.GetPackageManagerExplorer(req.GetInstance()) pme, release, err := instances.GetPackageManagerExplorer(req.GetInstance())
if pme == nil { if err != nil {
return nil, &cmderrors.InvalidInstanceError{} return nil, err
} }
defer release() defer release()
lm := instances.GetLibraryManager(req.GetInstance()) lm, err := instances.GetLibraryManager(req.GetInstance())
if lm == nil { if err != nil {
return nil, &cmderrors.InvalidInstanceError{} return nil, err
} }
logrus.Tracef("Compile %s for %s started", req.GetSketchPath(), req.GetFqbn()) logrus.Tracef("Compile %s for %s started", req.GetSketchPath(), req.GetFqbn())
......
...@@ -30,9 +30,9 @@ var tr = i18n.Tr ...@@ -30,9 +30,9 @@ var tr = i18n.Tr
// PlatformDownload FIXMEDOC // PlatformDownload FIXMEDOC
func PlatformDownload(ctx context.Context, req *rpc.PlatformDownloadRequest, downloadCB rpc.DownloadProgressCB) (*rpc.PlatformDownloadResponse, error) { func PlatformDownload(ctx context.Context, req *rpc.PlatformDownloadRequest, downloadCB rpc.DownloadProgressCB) (*rpc.PlatformDownloadResponse, error) {
pme, release := instances.GetPackageManagerExplorer(req.GetInstance()) pme, release, err := instances.GetPackageManagerExplorer(req.GetInstance())
if pme == nil { if err != nil {
return nil, &cmderrors.InvalidInstanceError{} return nil, err
} }
defer release() defer release()
......
...@@ -29,9 +29,9 @@ import ( ...@@ -29,9 +29,9 @@ import (
// PlatformInstall FIXMEDOC // PlatformInstall FIXMEDOC
func PlatformInstall(ctx context.Context, req *rpc.PlatformInstallRequest, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB) (*rpc.PlatformInstallResponse, error) { func PlatformInstall(ctx context.Context, req *rpc.PlatformInstallRequest, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB) (*rpc.PlatformInstallResponse, error) {
install := func() error { install := func() error {
pme, release := instances.GetPackageManagerExplorer(req.GetInstance()) pme, release, err := instances.GetPackageManagerExplorer(req.GetInstance())
if pme == nil { if err != nil {
return &cmderrors.InvalidInstanceError{} return err
} }
defer release() defer release()
......
...@@ -21,7 +21,6 @@ import ( ...@@ -21,7 +21,6 @@ import (
"strings" "strings"
"github.com/arduino/arduino-cli/commands" "github.com/arduino/arduino-cli/commands"
"github.com/arduino/arduino-cli/commands/cmderrors"
"github.com/arduino/arduino-cli/commands/internal/instances" "github.com/arduino/arduino-cli/commands/internal/instances"
"github.com/arduino/arduino-cli/internal/arduino/cores" "github.com/arduino/arduino-cli/internal/arduino/cores"
"github.com/arduino/arduino-cli/internal/arduino/utils" "github.com/arduino/arduino-cli/internal/arduino/utils"
...@@ -30,9 +29,9 @@ import ( ...@@ -30,9 +29,9 @@ import (
// PlatformSearch FIXMEDOC // PlatformSearch FIXMEDOC
func PlatformSearch(req *rpc.PlatformSearchRequest) (*rpc.PlatformSearchResponse, error) { func PlatformSearch(req *rpc.PlatformSearchRequest) (*rpc.PlatformSearchResponse, error) {
pme, release := instances.GetPackageManagerExplorer(req.GetInstance()) pme, release, err := instances.GetPackageManagerExplorer(req.GetInstance())
if pme == nil { if err != nil {
return nil, &cmderrors.InvalidInstanceError{} return nil, err
} }
defer release() defer release()
......
...@@ -38,8 +38,8 @@ func PlatformUninstall(ctx context.Context, req *rpc.PlatformUninstallRequest, t ...@@ -38,8 +38,8 @@ func PlatformUninstall(ctx context.Context, req *rpc.PlatformUninstallRequest, t
// platformUninstall is the implementation of platform unistaller // platformUninstall is the implementation of platform unistaller
func platformUninstall(ctx context.Context, req *rpc.PlatformUninstallRequest, taskCB rpc.TaskProgressCB) error { func platformUninstall(ctx context.Context, req *rpc.PlatformUninstallRequest, taskCB rpc.TaskProgressCB) error {
pme, release := instances.GetPackageManagerExplorer(req.GetInstance()) pme, release, err := instances.GetPackageManagerExplorer(req.GetInstance())
if pme == nil { if err != nil {
return &cmderrors.InvalidInstanceError{} return &cmderrors.InvalidInstanceError{}
} }
defer release() defer release()
......
...@@ -19,7 +19,6 @@ import ( ...@@ -19,7 +19,6 @@ import (
"context" "context"
"github.com/arduino/arduino-cli/commands" "github.com/arduino/arduino-cli/commands"
"github.com/arduino/arduino-cli/commands/cmderrors"
"github.com/arduino/arduino-cli/commands/internal/instances" "github.com/arduino/arduino-cli/commands/internal/instances"
"github.com/arduino/arduino-cli/internal/arduino/cores" "github.com/arduino/arduino-cli/internal/arduino/cores"
"github.com/arduino/arduino-cli/internal/arduino/cores/packagemanager" "github.com/arduino/arduino-cli/internal/arduino/cores/packagemanager"
...@@ -29,9 +28,9 @@ import ( ...@@ -29,9 +28,9 @@ import (
// PlatformUpgrade FIXMEDOC // PlatformUpgrade FIXMEDOC
func PlatformUpgrade(ctx context.Context, req *rpc.PlatformUpgradeRequest, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB) (*rpc.PlatformUpgradeResponse, error) { func PlatformUpgrade(ctx context.Context, req *rpc.PlatformUpgradeRequest, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB) (*rpc.PlatformUpgradeResponse, error) {
upgrade := func() (*cores.PlatformRelease, error) { upgrade := func() (*cores.PlatformRelease, error) {
pme, release := instances.GetPackageManagerExplorer(req.GetInstance()) pme, release, err := instances.GetPackageManagerExplorer(req.GetInstance())
if pme == nil { if err != nil {
return nil, &cmderrors.InvalidInstanceError{} return nil, err
} }
defer release() defer release()
......
...@@ -44,9 +44,9 @@ var tr = i18n.Tr ...@@ -44,9 +44,9 @@ var tr = i18n.Tr
func Debug(ctx context.Context, req *rpc.GetDebugConfigRequest, inStream io.Reader, out io.Writer, interrupt <-chan os.Signal) (*rpc.DebugResponse, error) { func Debug(ctx context.Context, req *rpc.GetDebugConfigRequest, inStream io.Reader, out io.Writer, interrupt <-chan os.Signal) (*rpc.DebugResponse, error) {
// Get debugging command line to run debugger // Get debugging command line to run debugger
pme, release := instances.GetPackageManagerExplorer(req.GetInstance()) pme, release, err := instances.GetPackageManagerExplorer(req.GetInstance())
if pme == nil { if err != nil {
return nil, &cmderrors.InvalidInstanceError{} return nil, err
} }
defer release() defer release()
......
...@@ -38,9 +38,9 @@ import ( ...@@ -38,9 +38,9 @@ import (
// GetDebugConfig returns metadata to start debugging with the specified board // GetDebugConfig returns metadata to start debugging with the specified board
func GetDebugConfig(ctx context.Context, req *rpc.GetDebugConfigRequest) (*rpc.GetDebugConfigResponse, error) { func GetDebugConfig(ctx context.Context, req *rpc.GetDebugConfigRequest) (*rpc.GetDebugConfigResponse, error) {
pme, release := instances.GetPackageManagerExplorer(req.GetInstance()) pme, release, err := instances.GetPackageManagerExplorer(req.GetInstance())
if pme == nil { if err != nil {
return nil, &cmderrors.InvalidInstanceError{} return nil, err
} }
defer release() defer release()
return getDebugProperties(req, pme, false) return getDebugProperties(req, pme, false)
...@@ -48,9 +48,9 @@ func GetDebugConfig(ctx context.Context, req *rpc.GetDebugConfigRequest) (*rpc.G ...@@ -48,9 +48,9 @@ func GetDebugConfig(ctx context.Context, req *rpc.GetDebugConfigRequest) (*rpc.G
// IsDebugSupported checks if the given board/programmer configuration supports debugging. // IsDebugSupported checks if the given board/programmer configuration supports debugging.
func IsDebugSupported(ctx context.Context, req *rpc.IsDebugSupportedRequest) (*rpc.IsDebugSupportedResponse, error) { func IsDebugSupported(ctx context.Context, req *rpc.IsDebugSupportedRequest) (*rpc.IsDebugSupportedResponse, error) {
pme, release := instances.GetPackageManagerExplorer(req.GetInstance()) pme, release, err := instances.GetPackageManagerExplorer(req.GetInstance())
if pme == nil { if err != nil {
return nil, &cmderrors.InvalidInstanceError{} return nil, err
} }
defer release() defer release()
configRequest := &rpc.GetDebugConfigRequest{ configRequest := &rpc.GetDebugConfigRequest{
......
...@@ -190,7 +190,11 @@ func Init(req *rpc.InitRequest, responseCallback func(r *rpc.InitResponse)) erro ...@@ -190,7 +190,11 @@ func Init(req *rpc.InitRequest, responseCallback func(r *rpc.InitResponse)) erro
// after reinitializing an instance after installing or uninstalling a core. // after reinitializing an instance after installing or uninstalling a core.
// If this is not done the information of the uninstall core is kept in memory, // If this is not done the information of the uninstall core is kept in memory,
// even if it should not. // even if it should not.
pmb, commitPackageManager := instances.GetPackageManager(instance).NewBuilder() pm, err := instances.GetPackageManager(instance)
if err != nil {
return err
}
pmb, commitPackageManager := pm.NewBuilder()
// Load packages index // Load packages index
for _, URL := range allPackageIndexUrls { for _, URL := range allPackageIndexUrls {
...@@ -285,7 +289,10 @@ func Init(req *rpc.InitRequest, responseCallback func(r *rpc.InitResponse)) erro ...@@ -285,7 +289,10 @@ func Init(req *rpc.InitRequest, responseCallback func(r *rpc.InitResponse)) erro
commitPackageManager() commitPackageManager()
} }
pme, release := instances.GetPackageManagerExplorer(instance) pme, release, err := instances.GetPackageManagerExplorer(instance)
if err != nil {
return err
}
defer release() defer release()
for _, err := range pme.LoadDiscoveries() { for _, err := range pme.LoadDiscoveries() {
...@@ -389,9 +396,9 @@ func Destroy(ctx context.Context, req *rpc.DestroyRequest) (*rpc.DestroyResponse ...@@ -389,9 +396,9 @@ func Destroy(ctx context.Context, req *rpc.DestroyRequest) (*rpc.DestroyResponse
// UpdateLibrariesIndex updates the library_index.json // UpdateLibrariesIndex updates the library_index.json
func UpdateLibrariesIndex(ctx context.Context, req *rpc.UpdateLibrariesIndexRequest, downloadCB rpc.DownloadProgressCB) error { func UpdateLibrariesIndex(ctx context.Context, req *rpc.UpdateLibrariesIndexRequest, downloadCB rpc.DownloadProgressCB) error {
logrus.Info("Updating libraries index") logrus.Info("Updating libraries index")
lm := instances.GetLibraryManager(req.GetInstance()) lm, err := instances.GetLibraryManager(req.GetInstance())
if lm == nil { if err != nil {
return &cmderrors.InvalidInstanceError{} return err
} }
if err := lm.IndexFile.Parent().MkdirAll(); err != nil { if err := lm.IndexFile.Parent().MkdirAll(); err != nil {
......
...@@ -3,6 +3,7 @@ package instances ...@@ -3,6 +3,7 @@ package instances
import ( import (
"sync" "sync"
"github.com/arduino/arduino-cli/commands/cmderrors"
"github.com/arduino/arduino-cli/internal/arduino/cores/packagemanager" "github.com/arduino/arduino-cli/internal/arduino/cores/packagemanager"
"github.com/arduino/arduino-cli/internal/arduino/libraries/librariesmanager" "github.com/arduino/arduino-cli/internal/arduino/libraries/librariesmanager"
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1" rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
...@@ -26,36 +27,37 @@ var instancesMux sync.Mutex ...@@ -26,36 +27,37 @@ var instancesMux sync.Mutex
// GetPackageManager returns a PackageManager. If the package manager is not found // GetPackageManager returns a PackageManager. If the package manager is not found
// (because the instance is invalid or has been destroyed), nil is returned. // (because the instance is invalid or has been destroyed), nil is returned.
// Deprecated: use GetPackageManagerExplorer instead. // Deprecated: use GetPackageManagerExplorer instead.
func GetPackageManager(inst *rpc.Instance) *packagemanager.PackageManager { func GetPackageManager(inst *rpc.Instance) (*packagemanager.PackageManager, error) {
instancesMux.Lock() instancesMux.Lock()
i := instances[inst.GetId()] i := instances[inst.GetId()]
instancesMux.Unlock() instancesMux.Unlock()
if i == nil { if i == nil {
return nil return nil, &cmderrors.InvalidInstanceError{}
} }
return i.pm return i.pm, nil
} }
// GetPackageManagerExplorer returns a new package manager Explorer. The // GetPackageManagerExplorer returns a new package manager Explorer. The
// explorer holds a read lock on the underlying PackageManager and it should // explorer holds a read lock on the underlying PackageManager and it should
// be released by calling the returned "release" function. // be released by calling the returned "release" function.
func GetPackageManagerExplorer(req *rpc.Instance) (explorer *packagemanager.Explorer, release func()) { func GetPackageManagerExplorer(req *rpc.Instance) (explorer *packagemanager.Explorer, release func(), _err error) {
pm := GetPackageManager(req) pm, err := GetPackageManager(req)
if pm == nil { if err != nil {
return nil, nil return nil, nil, err
} }
return pm.NewExplorer() pme, release := pm.NewExplorer()
return pme, release, nil
} }
// GetLibraryManager returns the library manager for the given instance. // GetLibraryManager returns the library manager for the given instance.
func GetLibraryManager(inst *rpc.Instance) *librariesmanager.LibrariesManager { func GetLibraryManager(inst *rpc.Instance) (*librariesmanager.LibrariesManager, error) {
instancesMux.Lock() instancesMux.Lock()
i := instances[inst.GetId()] i := instances[inst.GetId()]
instancesMux.Unlock() instancesMux.Unlock()
if i == nil { if i == nil {
return nil return nil, &cmderrors.InvalidInstanceError{}
} }
return i.lm return i.lm, nil
} }
// SetLibraryManager sets the library manager for the given instance. // SetLibraryManager sets the library manager for the given instance.
......
...@@ -35,9 +35,9 @@ var tr = i18n.Tr ...@@ -35,9 +35,9 @@ var tr = i18n.Tr
func LibraryDownload(ctx context.Context, req *rpc.LibraryDownloadRequest, downloadCB rpc.DownloadProgressCB) (*rpc.LibraryDownloadResponse, error) { func LibraryDownload(ctx context.Context, req *rpc.LibraryDownloadRequest, downloadCB rpc.DownloadProgressCB) (*rpc.LibraryDownloadResponse, error) {
logrus.Info("Executing `arduino-cli lib download`") logrus.Info("Executing `arduino-cli lib download`")
lm := instances.GetLibraryManager(req.GetInstance()) lm, err := instances.GetLibraryManager(req.GetInstance())
if lm == nil { if err != nil {
return nil, &cmderrors.InvalidInstanceError{} return nil, err
} }
logrus.Info("Preparing download") logrus.Info("Preparing download")
......
...@@ -33,9 +33,9 @@ import ( ...@@ -33,9 +33,9 @@ import (
// LibraryInstall resolves the library dependencies, then downloads and installs the libraries into the install location. // LibraryInstall resolves the library dependencies, then downloads and installs the libraries into the install location.
func LibraryInstall(ctx context.Context, req *rpc.LibraryInstallRequest, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB) error { func LibraryInstall(ctx context.Context, req *rpc.LibraryInstallRequest, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB) error {
lm := instances.GetLibraryManager(req.GetInstance()) lm, err := instances.GetLibraryManager(req.GetInstance())
if lm == nil { if err != nil {
return &cmderrors.InvalidInstanceError{} return err
} }
toInstall := map[string]*rpc.LibraryDependencyStatus{} toInstall := map[string]*rpc.LibraryDependencyStatus{}
...@@ -145,7 +145,10 @@ func installLibrary(lm *librariesmanager.LibrariesManager, libRelease *libraries ...@@ -145,7 +145,10 @@ func installLibrary(lm *librariesmanager.LibrariesManager, libRelease *libraries
// ZipLibraryInstall FIXMEDOC // ZipLibraryInstall FIXMEDOC
func ZipLibraryInstall(ctx context.Context, req *rpc.ZipLibraryInstallRequest, taskCB rpc.TaskProgressCB) error { func ZipLibraryInstall(ctx context.Context, req *rpc.ZipLibraryInstallRequest, taskCB rpc.TaskProgressCB) error {
lm := instances.GetLibraryManager(req.GetInstance()) lm, err := instances.GetLibraryManager(req.GetInstance())
if err != nil {
return err
}
if err := lm.InstallZipLib(ctx, paths.New(req.GetPath()), req.GetOverwrite()); err != nil { if err := lm.InstallZipLib(ctx, paths.New(req.GetPath()), req.GetOverwrite()); err != nil {
return &cmderrors.FailedLibraryInstallError{Cause: err} return &cmderrors.FailedLibraryInstallError{Cause: err}
} }
...@@ -155,7 +158,10 @@ func ZipLibraryInstall(ctx context.Context, req *rpc.ZipLibraryInstallRequest, t ...@@ -155,7 +158,10 @@ func ZipLibraryInstall(ctx context.Context, req *rpc.ZipLibraryInstallRequest, t
// GitLibraryInstall FIXMEDOC // GitLibraryInstall FIXMEDOC
func GitLibraryInstall(ctx context.Context, req *rpc.GitLibraryInstallRequest, taskCB rpc.TaskProgressCB) error { func GitLibraryInstall(ctx context.Context, req *rpc.GitLibraryInstallRequest, taskCB rpc.TaskProgressCB) error {
lm := instances.GetLibraryManager(req.GetInstance()) lm, err := instances.GetLibraryManager(req.GetInstance())
if err != nil {
return err
}
if err := lm.InstallGitLib(req.GetUrl(), req.GetOverwrite()); err != nil { if err := lm.InstallGitLib(req.GetUrl(), req.GetOverwrite()); err != nil {
return &cmderrors.FailedLibraryInstallError{Cause: err} return &cmderrors.FailedLibraryInstallError{Cause: err}
} }
......
...@@ -36,15 +36,15 @@ type installedLib struct { ...@@ -36,15 +36,15 @@ type installedLib struct {
// LibraryList FIXMEDOC // LibraryList FIXMEDOC
func LibraryList(ctx context.Context, req *rpc.LibraryListRequest) (*rpc.LibraryListResponse, error) { func LibraryList(ctx context.Context, req *rpc.LibraryListRequest) (*rpc.LibraryListResponse, error) {
pme, release := instances.GetPackageManagerExplorer(req.GetInstance()) pme, release, err := instances.GetPackageManagerExplorer(req.GetInstance())
if pme == nil { if err != nil {
return nil, &cmderrors.InvalidInstanceError{} return nil, err
} }
defer release() defer release()
lm := instances.GetLibraryManager(req.GetInstance()) lm, err := instances.GetLibraryManager(req.GetInstance())
if lm == nil { if err != nil {
return nil, &cmderrors.InvalidInstanceError{} return nil, err
} }
nameFilter := strings.ToLower(req.GetName()) nameFilter := strings.ToLower(req.GetName())
......
...@@ -30,9 +30,9 @@ import ( ...@@ -30,9 +30,9 @@ import (
// LibraryResolveDependencies FIXMEDOC // LibraryResolveDependencies FIXMEDOC
func LibraryResolveDependencies(ctx context.Context, req *rpc.LibraryResolveDependenciesRequest) (*rpc.LibraryResolveDependenciesResponse, error) { func LibraryResolveDependencies(ctx context.Context, req *rpc.LibraryResolveDependenciesRequest) (*rpc.LibraryResolveDependenciesResponse, error) {
lm := instances.GetLibraryManager(req.GetInstance()) lm, err := instances.GetLibraryManager(req.GetInstance())
if lm == nil { if err != nil {
return nil, &cmderrors.InvalidInstanceError{} return nil, err
} }
// Search the requested lib // Search the requested lib
......
...@@ -20,7 +20,6 @@ import ( ...@@ -20,7 +20,6 @@ import (
"sort" "sort"
"strings" "strings"
"github.com/arduino/arduino-cli/commands/cmderrors"
"github.com/arduino/arduino-cli/commands/internal/instances" "github.com/arduino/arduino-cli/commands/internal/instances"
"github.com/arduino/arduino-cli/internal/arduino/libraries/librariesindex" "github.com/arduino/arduino-cli/internal/arduino/libraries/librariesindex"
"github.com/arduino/arduino-cli/internal/arduino/libraries/librariesmanager" "github.com/arduino/arduino-cli/internal/arduino/libraries/librariesmanager"
...@@ -30,9 +29,9 @@ import ( ...@@ -30,9 +29,9 @@ import (
// LibrarySearch FIXMEDOC // LibrarySearch FIXMEDOC
func LibrarySearch(ctx context.Context, req *rpc.LibrarySearchRequest) (*rpc.LibrarySearchResponse, error) { func LibrarySearch(ctx context.Context, req *rpc.LibrarySearchRequest) (*rpc.LibrarySearchResponse, error) {
lm := instances.GetLibraryManager(req.GetInstance()) lm, err := instances.GetLibraryManager(req.GetInstance())
if lm == nil { if err != nil {
return nil, &cmderrors.InvalidInstanceError{} return nil, err
} }
return searchLibrary(req, lm), nil return searchLibrary(req, lm), nil
} }
......
...@@ -27,7 +27,11 @@ import ( ...@@ -27,7 +27,11 @@ import (
// LibraryUninstall FIXMEDOC // LibraryUninstall FIXMEDOC
func LibraryUninstall(ctx context.Context, req *rpc.LibraryUninstallRequest, taskCB rpc.TaskProgressCB) error { func LibraryUninstall(ctx context.Context, req *rpc.LibraryUninstallRequest, taskCB rpc.TaskProgressCB) error {
lm := instances.GetLibraryManager(req.GetInstance()) lm, err := instances.GetLibraryManager(req.GetInstance())
if err != nil {
return err
}
ref, err := createLibIndexReference(lm, req) ref, err := createLibIndexReference(lm, req)
if err != nil { if err != nil {
return &cmderrors.InvalidLibraryError{Cause: err} return &cmderrors.InvalidLibraryError{Cause: err}
......
...@@ -26,9 +26,9 @@ import ( ...@@ -26,9 +26,9 @@ import (
// LibraryUpgradeAll upgrades all the available libraries // LibraryUpgradeAll upgrades all the available libraries
func LibraryUpgradeAll(req *rpc.LibraryUpgradeAllRequest, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB) error { func LibraryUpgradeAll(req *rpc.LibraryUpgradeAllRequest, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB) error {
lm := instances.GetLibraryManager(req.GetInstance()) lm, err := instances.GetLibraryManager(req.GetInstance())
if lm == nil { if err != nil {
return &cmderrors.InvalidInstanceError{} return err
} }
if err := upgrade(req.GetInstance(), listLibraries(lm, true, false), downloadCB, taskCB); err != nil { if err := upgrade(req.GetInstance(), listLibraries(lm, true, false), downloadCB, taskCB); err != nil {
...@@ -44,9 +44,9 @@ func LibraryUpgradeAll(req *rpc.LibraryUpgradeAllRequest, downloadCB rpc.Downloa ...@@ -44,9 +44,9 @@ func LibraryUpgradeAll(req *rpc.LibraryUpgradeAllRequest, downloadCB rpc.Downloa
// LibraryUpgrade upgrades a library // LibraryUpgrade upgrades a library
func LibraryUpgrade(ctx context.Context, req *rpc.LibraryUpgradeRequest, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB) error { func LibraryUpgrade(ctx context.Context, req *rpc.LibraryUpgradeRequest, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB) error {
lm := instances.GetLibraryManager(req.GetInstance()) lm, err := instances.GetLibraryManager(req.GetInstance())
if lm == nil { if err != nil {
return &cmderrors.InvalidInstanceError{} return err
} }
// Get the library to upgrade // Get the library to upgrade
......
...@@ -61,9 +61,9 @@ func (p *PortProxy) Close() error { ...@@ -61,9 +61,9 @@ func (p *PortProxy) Close() error {
// Monitor opens a communication port. It returns a PortProxy to communicate with the port and a PortDescriptor // Monitor opens a communication port. It returns a PortProxy to communicate with the port and a PortDescriptor
// that describes the available configuration settings. // that describes the available configuration settings.
func Monitor(ctx context.Context, req *rpc.MonitorRequest) (*PortProxy, *pluggableMonitor.PortDescriptor, error) { func Monitor(ctx context.Context, req *rpc.MonitorRequest) (*PortProxy, *pluggableMonitor.PortDescriptor, error) {
pme, release := instances.GetPackageManagerExplorer(req.GetInstance()) pme, release, err := instances.GetPackageManagerExplorer(req.GetInstance())
if pme == nil { if err != nil {
return nil, nil, &cmderrors.InvalidInstanceError{} return nil, nil, err
} }
defer release() defer release()
......
...@@ -26,9 +26,9 @@ import ( ...@@ -26,9 +26,9 @@ import (
// EnumerateMonitorPortSettings returns a description of the configuration settings of a monitor port // EnumerateMonitorPortSettings returns a description of the configuration settings of a monitor port
func EnumerateMonitorPortSettings(ctx context.Context, req *rpc.EnumerateMonitorPortSettingsRequest) (*rpc.EnumerateMonitorPortSettingsResponse, error) { func EnumerateMonitorPortSettings(ctx context.Context, req *rpc.EnumerateMonitorPortSettingsRequest) (*rpc.EnumerateMonitorPortSettingsResponse, error) {
pme, release := instances.GetPackageManagerExplorer(req.GetInstance()) pme, release, err := instances.GetPackageManagerExplorer(req.GetInstance())
if pme == nil { if err != nil {
return nil, &cmderrors.InvalidInstanceError{} return nil, err
} }
defer release() defer release()
......
...@@ -19,7 +19,6 @@ import ( ...@@ -19,7 +19,6 @@ import (
"context" "context"
"io" "io"
"github.com/arduino/arduino-cli/commands/cmderrors"
"github.com/arduino/arduino-cli/commands/internal/instances" "github.com/arduino/arduino-cli/commands/internal/instances"
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1" rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
...@@ -33,13 +32,13 @@ func BurnBootloader(ctx context.Context, req *rpc.BurnBootloaderRequest, outStre ...@@ -33,13 +32,13 @@ func BurnBootloader(ctx context.Context, req *rpc.BurnBootloaderRequest, outStre
WithField("programmer", req.GetProgrammer()). WithField("programmer", req.GetProgrammer()).
Trace("BurnBootloader started", req.GetFqbn()) Trace("BurnBootloader started", req.GetFqbn())
pme, release := instances.GetPackageManagerExplorer(req.GetInstance()) pme, release, err := instances.GetPackageManagerExplorer(req.GetInstance())
if pme == nil { if err != nil {
return nil, &cmderrors.InvalidInstanceError{} return nil, err
} }
defer release() defer release()
_, err := runProgramAction( if _, err := runProgramAction(
pme, pme,
nil, // sketch nil, // sketch
"", // importFile "", // importFile
...@@ -54,8 +53,7 @@ func BurnBootloader(ctx context.Context, req *rpc.BurnBootloaderRequest, outStre ...@@ -54,8 +53,7 @@ func BurnBootloader(ctx context.Context, req *rpc.BurnBootloaderRequest, outStre
errStream, errStream,
req.GetDryRun(), req.GetDryRun(),
map[string]string{}, // User fields map[string]string{}, // User fields
) ); err != nil {
if err != nil {
return nil, err return nil, err
} }
return &rpc.BurnBootloaderResponse{}, nil return &rpc.BurnBootloaderResponse{}, nil
......
...@@ -26,9 +26,9 @@ import ( ...@@ -26,9 +26,9 @@ import (
// ListProgrammersAvailableForUpload FIXMEDOC // ListProgrammersAvailableForUpload FIXMEDOC
func ListProgrammersAvailableForUpload(ctx context.Context, req *rpc.ListProgrammersAvailableForUploadRequest) (*rpc.ListProgrammersAvailableForUploadResponse, error) { func ListProgrammersAvailableForUpload(ctx context.Context, req *rpc.ListProgrammersAvailableForUploadRequest) (*rpc.ListProgrammersAvailableForUploadResponse, error) {
pme, release := instances.GetPackageManagerExplorer(req.GetInstance()) pme, release, err := instances.GetPackageManagerExplorer(req.GetInstance())
if pme == nil { if err != nil {
return nil, &cmderrors.InvalidInstanceError{} return nil, err
} }
defer release() defer release()
......
...@@ -49,12 +49,11 @@ func SupportedUserFields(ctx context.Context, req *rpc.SupportedUserFieldsReques ...@@ -49,12 +49,11 @@ func SupportedUserFields(ctx context.Context, req *rpc.SupportedUserFieldsReques
return nil, &cmderrors.MissingPortProtocolError{} return nil, &cmderrors.MissingPortProtocolError{}
} }
pme, release := instances.GetPackageManagerExplorer(req.GetInstance()) pme, release, err := instances.GetPackageManagerExplorer(req.GetInstance())
defer release() if err != nil {
return nil, err
if pme == nil {
return nil, &cmderrors.InvalidInstanceError{}
} }
defer release()
fqbn, err := cores.ParseFQBN(req.GetFqbn()) fqbn, err := cores.ParseFQBN(req.GetFqbn())
if err != nil { if err != nil {
...@@ -136,9 +135,9 @@ func Upload(ctx context.Context, req *rpc.UploadRequest, outStream io.Writer, er ...@@ -136,9 +135,9 @@ func Upload(ctx context.Context, req *rpc.UploadRequest, outStream io.Writer, er
return nil, &cmderrors.CantOpenSketchError{Cause: err} return nil, &cmderrors.CantOpenSketchError{Cause: err}
} }
pme, pmeRelease := instances.GetPackageManagerExplorer(req.GetInstance()) pme, pmeRelease, err := instances.GetPackageManagerExplorer(req.GetInstance())
if pme == nil { if err != nil {
return nil, &cmderrors.InvalidInstanceError{} return nil, err
} }
defer pmeRelease() defer pmeRelease()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment