diff --git a/commands/board/details.go b/commands/board/details.go index 604f6cb4553..22cfb36a354 100644 --- a/commands/board/details.go +++ b/commands/board/details.go @@ -28,9 +28,9 @@ import ( // 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 func Details(ctx context.Context, req *rpc.BoardDetailsRequest) (*rpc.BoardDetailsResponse, error) { - pme, release := instances.GetPackageManagerExplorer(req.GetInstance()) - if pme == nil { - return nil, &cmderrors.InvalidInstanceError{} + pme, release, err := instances.GetPackageManagerExplorer(req.GetInstance()) + if err != nil { + return nil, err } defer release() diff --git a/commands/board/list.go b/commands/board/list.go index 18d2d815e55..22a66b524c3 100644 --- a/commands/board/list.go +++ b/commands/board/list.go @@ -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 // are returned. func List(req *rpc.BoardListRequest) (r []*rpc.DetectedPort, discoveryStartErrors []error, e error) { - pme, release := instances.GetPackageManagerExplorer(req.GetInstance()) - if pme == nil { - return nil, nil, &cmderrors.InvalidInstanceError{} + pme, release, err := instances.GetPackageManagerExplorer(req.GetInstance()) + if err != nil { + return nil, nil, err } defer release() @@ -260,9 +260,9 @@ func hasMatchingBoard(b *rpc.DetectedPort, fqbnFilter *cores.FQBN) bool { // Watch returns a channel that receives boards connection and disconnection events. func Watch(ctx context.Context, req *rpc.BoardListWatchRequest) (<-chan *rpc.BoardListWatchResponse, error) { - pme, release := instances.GetPackageManagerExplorer(req.GetInstance()) - if pme == nil { - return nil, &cmderrors.InvalidInstanceError{} + pme, release, err := instances.GetPackageManagerExplorer(req.GetInstance()) + if err != nil { + return nil, err } defer release() dm := pme.DiscoveryManager() diff --git a/commands/board/listall.go b/commands/board/listall.go index 8b03ed890f1..2b4e4d153e2 100644 --- a/commands/board/listall.go +++ b/commands/board/listall.go @@ -21,7 +21,6 @@ import ( "strings" "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/internal/arduino/cores" "github.com/arduino/arduino-cli/internal/arduino/utils" @@ -30,9 +29,9 @@ import ( // ListAll FIXMEDOC func ListAll(ctx context.Context, req *rpc.BoardListAllRequest) (*rpc.BoardListAllResponse, error) { - pme, release := instances.GetPackageManagerExplorer(req.GetInstance()) - if pme == nil { - return nil, &cmderrors.InvalidInstanceError{} + pme, release, err := instances.GetPackageManagerExplorer(req.GetInstance()) + if err != nil { + return nil, err } defer release() diff --git a/commands/board/search.go b/commands/board/search.go index 08bb388b240..00ea3ac1e20 100644 --- a/commands/board/search.go +++ b/commands/board/search.go @@ -21,7 +21,6 @@ import ( "strings" "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/internal/arduino/utils" rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1" @@ -32,9 +31,9 @@ import ( // installed. Note that platforms that are not installed don't include boards' FQBNs. // If no search argument is used all boards are returned. func Search(ctx context.Context, req *rpc.BoardSearchRequest) (*rpc.BoardSearchResponse, error) { - pme, release := instances.GetPackageManagerExplorer(req.GetInstance()) - if pme == nil { - return nil, &cmderrors.InvalidInstanceError{} + pme, release, err := instances.GetPackageManagerExplorer(req.GetInstance()) + if err != nil { + return nil, err } defer release() diff --git a/commands/compile/compile.go b/commands/compile/compile.go index 739acad05fb..5926eda281a 100644 --- a/commands/compile/compile.go +++ b/commands/compile/compile.go @@ -57,15 +57,15 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream exportBinaries = reqExportBinaries.GetValue() } - pme, release := instances.GetPackageManagerExplorer(req.GetInstance()) - if pme == nil { - return nil, &cmderrors.InvalidInstanceError{} + pme, release, err := instances.GetPackageManagerExplorer(req.GetInstance()) + if err != nil { + return nil, err } defer release() - lm := instances.GetLibraryManager(req.GetInstance()) - if lm == nil { - return nil, &cmderrors.InvalidInstanceError{} + lm, err := instances.GetLibraryManager(req.GetInstance()) + if err != nil { + return nil, err } logrus.Tracef("Compile %s for %s started", req.GetSketchPath(), req.GetFqbn()) diff --git a/commands/core/download.go b/commands/core/download.go index c166af6585a..a64d35e4ae1 100644 --- a/commands/core/download.go +++ b/commands/core/download.go @@ -30,9 +30,9 @@ var tr = i18n.Tr // PlatformDownload FIXMEDOC func PlatformDownload(ctx context.Context, req *rpc.PlatformDownloadRequest, downloadCB rpc.DownloadProgressCB) (*rpc.PlatformDownloadResponse, error) { - pme, release := instances.GetPackageManagerExplorer(req.GetInstance()) - if pme == nil { - return nil, &cmderrors.InvalidInstanceError{} + pme, release, err := instances.GetPackageManagerExplorer(req.GetInstance()) + if err != nil { + return nil, err } defer release() diff --git a/commands/core/install.go b/commands/core/install.go index 01a37736649..ce012081526 100644 --- a/commands/core/install.go +++ b/commands/core/install.go @@ -29,9 +29,9 @@ import ( // PlatformInstall FIXMEDOC func PlatformInstall(ctx context.Context, req *rpc.PlatformInstallRequest, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB) (*rpc.PlatformInstallResponse, error) { install := func() error { - pme, release := instances.GetPackageManagerExplorer(req.GetInstance()) - if pme == nil { - return &cmderrors.InvalidInstanceError{} + pme, release, err := instances.GetPackageManagerExplorer(req.GetInstance()) + if err != nil { + return err } defer release() diff --git a/commands/core/search.go b/commands/core/search.go index 9631aaae6b2..f68712c17e3 100644 --- a/commands/core/search.go +++ b/commands/core/search.go @@ -21,7 +21,6 @@ import ( "strings" "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/internal/arduino/cores" "github.com/arduino/arduino-cli/internal/arduino/utils" @@ -30,9 +29,9 @@ import ( // PlatformSearch FIXMEDOC func PlatformSearch(req *rpc.PlatformSearchRequest) (*rpc.PlatformSearchResponse, error) { - pme, release := instances.GetPackageManagerExplorer(req.GetInstance()) - if pme == nil { - return nil, &cmderrors.InvalidInstanceError{} + pme, release, err := instances.GetPackageManagerExplorer(req.GetInstance()) + if err != nil { + return nil, err } defer release() diff --git a/commands/core/uninstall.go b/commands/core/uninstall.go index c95d9e1afb4..d1c826ad210 100644 --- a/commands/core/uninstall.go +++ b/commands/core/uninstall.go @@ -38,8 +38,8 @@ func PlatformUninstall(ctx context.Context, req *rpc.PlatformUninstallRequest, t // platformUninstall is the implementation of platform unistaller func platformUninstall(ctx context.Context, req *rpc.PlatformUninstallRequest, taskCB rpc.TaskProgressCB) error { - pme, release := instances.GetPackageManagerExplorer(req.GetInstance()) - if pme == nil { + pme, release, err := instances.GetPackageManagerExplorer(req.GetInstance()) + if err != nil { return &cmderrors.InvalidInstanceError{} } defer release() diff --git a/commands/core/upgrade.go b/commands/core/upgrade.go index cecb2e721d8..57ba8de045e 100644 --- a/commands/core/upgrade.go +++ b/commands/core/upgrade.go @@ -19,7 +19,6 @@ import ( "context" "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/internal/arduino/cores" "github.com/arduino/arduino-cli/internal/arduino/cores/packagemanager" @@ -29,9 +28,9 @@ import ( // PlatformUpgrade FIXMEDOC func PlatformUpgrade(ctx context.Context, req *rpc.PlatformUpgradeRequest, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB) (*rpc.PlatformUpgradeResponse, error) { upgrade := func() (*cores.PlatformRelease, error) { - pme, release := instances.GetPackageManagerExplorer(req.GetInstance()) - if pme == nil { - return nil, &cmderrors.InvalidInstanceError{} + pme, release, err := instances.GetPackageManagerExplorer(req.GetInstance()) + if err != nil { + return nil, err } defer release() diff --git a/commands/debug/debug.go b/commands/debug/debug.go index afecc276439..431c8fcb830 100644 --- a/commands/debug/debug.go +++ b/commands/debug/debug.go @@ -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) { // Get debugging command line to run debugger - pme, release := instances.GetPackageManagerExplorer(req.GetInstance()) - if pme == nil { - return nil, &cmderrors.InvalidInstanceError{} + pme, release, err := instances.GetPackageManagerExplorer(req.GetInstance()) + if err != nil { + return nil, err } defer release() diff --git a/commands/debug/debug_info.go b/commands/debug/debug_info.go index 82e99b61eb0..b392ab6401c 100644 --- a/commands/debug/debug_info.go +++ b/commands/debug/debug_info.go @@ -38,9 +38,9 @@ import ( // GetDebugConfig returns metadata to start debugging with the specified board func GetDebugConfig(ctx context.Context, req *rpc.GetDebugConfigRequest) (*rpc.GetDebugConfigResponse, error) { - pme, release := instances.GetPackageManagerExplorer(req.GetInstance()) - if pme == nil { - return nil, &cmderrors.InvalidInstanceError{} + pme, release, err := instances.GetPackageManagerExplorer(req.GetInstance()) + if err != nil { + return nil, err } defer release() return getDebugProperties(req, pme, false) @@ -48,9 +48,9 @@ func GetDebugConfig(ctx context.Context, req *rpc.GetDebugConfigRequest) (*rpc.G // IsDebugSupported checks if the given board/programmer configuration supports debugging. func IsDebugSupported(ctx context.Context, req *rpc.IsDebugSupportedRequest) (*rpc.IsDebugSupportedResponse, error) { - pme, release := instances.GetPackageManagerExplorer(req.GetInstance()) - if pme == nil { - return nil, &cmderrors.InvalidInstanceError{} + pme, release, err := instances.GetPackageManagerExplorer(req.GetInstance()) + if err != nil { + return nil, err } defer release() configRequest := &rpc.GetDebugConfigRequest{ diff --git a/commands/instances.go b/commands/instances.go index a4a70d19370..41463cba257 100644 --- a/commands/instances.go +++ b/commands/instances.go @@ -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. // If this is not done the information of the uninstall core is kept in memory, // 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 for _, URL := range allPackageIndexUrls { @@ -285,7 +289,10 @@ func Init(req *rpc.InitRequest, responseCallback func(r *rpc.InitResponse)) erro commitPackageManager() } - pme, release := instances.GetPackageManagerExplorer(instance) + pme, release, err := instances.GetPackageManagerExplorer(instance) + if err != nil { + return err + } defer release() for _, err := range pme.LoadDiscoveries() { @@ -389,9 +396,9 @@ func Destroy(ctx context.Context, req *rpc.DestroyRequest) (*rpc.DestroyResponse // UpdateLibrariesIndex updates the library_index.json func UpdateLibrariesIndex(ctx context.Context, req *rpc.UpdateLibrariesIndexRequest, downloadCB rpc.DownloadProgressCB) error { logrus.Info("Updating libraries index") - lm := instances.GetLibraryManager(req.GetInstance()) - if lm == nil { - return &cmderrors.InvalidInstanceError{} + lm, err := instances.GetLibraryManager(req.GetInstance()) + if err != nil { + return err } if err := lm.IndexFile.Parent().MkdirAll(); err != nil { diff --git a/commands/internal/instances/instances.go b/commands/internal/instances/instances.go index 80be3c62da2..0621047f4bd 100644 --- a/commands/internal/instances/instances.go +++ b/commands/internal/instances/instances.go @@ -3,6 +3,7 @@ package instances import ( "sync" + "github.com/arduino/arduino-cli/commands/cmderrors" "github.com/arduino/arduino-cli/internal/arduino/cores/packagemanager" "github.com/arduino/arduino-cli/internal/arduino/libraries/librariesmanager" rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1" @@ -26,36 +27,37 @@ var instancesMux sync.Mutex // GetPackageManager returns a PackageManager. If the package manager is not found // (because the instance is invalid or has been destroyed), nil is returned. // Deprecated: use GetPackageManagerExplorer instead. -func GetPackageManager(inst *rpc.Instance) *packagemanager.PackageManager { +func GetPackageManager(inst *rpc.Instance) (*packagemanager.PackageManager, error) { instancesMux.Lock() i := instances[inst.GetId()] instancesMux.Unlock() if i == nil { - return nil + return nil, &cmderrors.InvalidInstanceError{} } - return i.pm + return i.pm, nil } // GetPackageManagerExplorer returns a new package manager Explorer. The // explorer holds a read lock on the underlying PackageManager and it should // be released by calling the returned "release" function. -func GetPackageManagerExplorer(req *rpc.Instance) (explorer *packagemanager.Explorer, release func()) { - pm := GetPackageManager(req) - if pm == nil { - return nil, nil +func GetPackageManagerExplorer(req *rpc.Instance) (explorer *packagemanager.Explorer, release func(), _err error) { + pm, err := GetPackageManager(req) + if err != 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. -func GetLibraryManager(inst *rpc.Instance) *librariesmanager.LibrariesManager { +func GetLibraryManager(inst *rpc.Instance) (*librariesmanager.LibrariesManager, error) { instancesMux.Lock() i := instances[inst.GetId()] instancesMux.Unlock() 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. diff --git a/commands/lib/download.go b/commands/lib/download.go index a8714413eb3..47b39c9c1fd 100644 --- a/commands/lib/download.go +++ b/commands/lib/download.go @@ -35,9 +35,9 @@ var tr = i18n.Tr func LibraryDownload(ctx context.Context, req *rpc.LibraryDownloadRequest, downloadCB rpc.DownloadProgressCB) (*rpc.LibraryDownloadResponse, error) { logrus.Info("Executing `arduino-cli lib download`") - lm := instances.GetLibraryManager(req.GetInstance()) - if lm == nil { - return nil, &cmderrors.InvalidInstanceError{} + lm, err := instances.GetLibraryManager(req.GetInstance()) + if err != nil { + return nil, err } logrus.Info("Preparing download") diff --git a/commands/lib/install.go b/commands/lib/install.go index 8c9e3e5794e..d0dcd846c67 100644 --- a/commands/lib/install.go +++ b/commands/lib/install.go @@ -33,9 +33,9 @@ import ( // 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 { - lm := instances.GetLibraryManager(req.GetInstance()) - if lm == nil { - return &cmderrors.InvalidInstanceError{} + lm, err := instances.GetLibraryManager(req.GetInstance()) + if err != nil { + return err } toInstall := map[string]*rpc.LibraryDependencyStatus{} @@ -145,7 +145,10 @@ func installLibrary(lm *librariesmanager.LibrariesManager, libRelease *libraries // ZipLibraryInstall FIXMEDOC 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 { return &cmderrors.FailedLibraryInstallError{Cause: err} } @@ -155,7 +158,10 @@ func ZipLibraryInstall(ctx context.Context, req *rpc.ZipLibraryInstallRequest, t // GitLibraryInstall FIXMEDOC 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 { return &cmderrors.FailedLibraryInstallError{Cause: err} } diff --git a/commands/lib/list.go b/commands/lib/list.go index e1fa300ea1f..0f2f7ec1339 100644 --- a/commands/lib/list.go +++ b/commands/lib/list.go @@ -36,15 +36,15 @@ type installedLib struct { // LibraryList FIXMEDOC func LibraryList(ctx context.Context, req *rpc.LibraryListRequest) (*rpc.LibraryListResponse, error) { - pme, release := instances.GetPackageManagerExplorer(req.GetInstance()) - if pme == nil { - return nil, &cmderrors.InvalidInstanceError{} + pme, release, err := instances.GetPackageManagerExplorer(req.GetInstance()) + if err != nil { + return nil, err } defer release() - lm := instances.GetLibraryManager(req.GetInstance()) - if lm == nil { - return nil, &cmderrors.InvalidInstanceError{} + lm, err := instances.GetLibraryManager(req.GetInstance()) + if err != nil { + return nil, err } nameFilter := strings.ToLower(req.GetName()) diff --git a/commands/lib/resolve_deps.go b/commands/lib/resolve_deps.go index 6131aa7b260..b1d17bbc42c 100644 --- a/commands/lib/resolve_deps.go +++ b/commands/lib/resolve_deps.go @@ -30,9 +30,9 @@ import ( // LibraryResolveDependencies FIXMEDOC func LibraryResolveDependencies(ctx context.Context, req *rpc.LibraryResolveDependenciesRequest) (*rpc.LibraryResolveDependenciesResponse, error) { - lm := instances.GetLibraryManager(req.GetInstance()) - if lm == nil { - return nil, &cmderrors.InvalidInstanceError{} + lm, err := instances.GetLibraryManager(req.GetInstance()) + if err != nil { + return nil, err } // Search the requested lib diff --git a/commands/lib/search.go b/commands/lib/search.go index e5492d4d0c7..cbd9bf4901a 100644 --- a/commands/lib/search.go +++ b/commands/lib/search.go @@ -20,7 +20,6 @@ import ( "sort" "strings" - "github.com/arduino/arduino-cli/commands/cmderrors" "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/librariesmanager" @@ -30,9 +29,9 @@ import ( // LibrarySearch FIXMEDOC func LibrarySearch(ctx context.Context, req *rpc.LibrarySearchRequest) (*rpc.LibrarySearchResponse, error) { - lm := instances.GetLibraryManager(req.GetInstance()) - if lm == nil { - return nil, &cmderrors.InvalidInstanceError{} + lm, err := instances.GetLibraryManager(req.GetInstance()) + if err != nil { + return nil, err } return searchLibrary(req, lm), nil } diff --git a/commands/lib/uninstall.go b/commands/lib/uninstall.go index e31823add46..a7ee8278c0b 100644 --- a/commands/lib/uninstall.go +++ b/commands/lib/uninstall.go @@ -27,7 +27,11 @@ import ( // LibraryUninstall FIXMEDOC 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) if err != nil { return &cmderrors.InvalidLibraryError{Cause: err} diff --git a/commands/lib/upgrade.go b/commands/lib/upgrade.go index aac357c00f3..824d645d648 100644 --- a/commands/lib/upgrade.go +++ b/commands/lib/upgrade.go @@ -26,9 +26,9 @@ import ( // LibraryUpgradeAll upgrades all the available libraries func LibraryUpgradeAll(req *rpc.LibraryUpgradeAllRequest, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB) error { - lm := instances.GetLibraryManager(req.GetInstance()) - if lm == nil { - return &cmderrors.InvalidInstanceError{} + lm, err := instances.GetLibraryManager(req.GetInstance()) + if err != nil { + return err } 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 // LibraryUpgrade upgrades a library func LibraryUpgrade(ctx context.Context, req *rpc.LibraryUpgradeRequest, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB) error { - lm := instances.GetLibraryManager(req.GetInstance()) - if lm == nil { - return &cmderrors.InvalidInstanceError{} + lm, err := instances.GetLibraryManager(req.GetInstance()) + if err != nil { + return err } // Get the library to upgrade diff --git a/commands/monitor/monitor.go b/commands/monitor/monitor.go index 31c30c2e34d..4f136181697 100644 --- a/commands/monitor/monitor.go +++ b/commands/monitor/monitor.go @@ -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 // that describes the available configuration settings. func Monitor(ctx context.Context, req *rpc.MonitorRequest) (*PortProxy, *pluggableMonitor.PortDescriptor, error) { - pme, release := instances.GetPackageManagerExplorer(req.GetInstance()) - if pme == nil { - return nil, nil, &cmderrors.InvalidInstanceError{} + pme, release, err := instances.GetPackageManagerExplorer(req.GetInstance()) + if err != nil { + return nil, nil, err } defer release() diff --git a/commands/monitor/settings.go b/commands/monitor/settings.go index 4f170b942d4..f6d41c15219 100644 --- a/commands/monitor/settings.go +++ b/commands/monitor/settings.go @@ -26,9 +26,9 @@ import ( // EnumerateMonitorPortSettings returns a description of the configuration settings of a monitor port func EnumerateMonitorPortSettings(ctx context.Context, req *rpc.EnumerateMonitorPortSettingsRequest) (*rpc.EnumerateMonitorPortSettingsResponse, error) { - pme, release := instances.GetPackageManagerExplorer(req.GetInstance()) - if pme == nil { - return nil, &cmderrors.InvalidInstanceError{} + pme, release, err := instances.GetPackageManagerExplorer(req.GetInstance()) + if err != nil { + return nil, err } defer release() diff --git a/commands/upload/burnbootloader.go b/commands/upload/burnbootloader.go index bf8bc3a608a..b589e573698 100644 --- a/commands/upload/burnbootloader.go +++ b/commands/upload/burnbootloader.go @@ -19,7 +19,6 @@ import ( "context" "io" - "github.com/arduino/arduino-cli/commands/cmderrors" "github.com/arduino/arduino-cli/commands/internal/instances" rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1" "github.com/sirupsen/logrus" @@ -33,13 +32,13 @@ func BurnBootloader(ctx context.Context, req *rpc.BurnBootloaderRequest, outStre WithField("programmer", req.GetProgrammer()). Trace("BurnBootloader started", req.GetFqbn()) - pme, release := instances.GetPackageManagerExplorer(req.GetInstance()) - if pme == nil { - return nil, &cmderrors.InvalidInstanceError{} + pme, release, err := instances.GetPackageManagerExplorer(req.GetInstance()) + if err != nil { + return nil, err } defer release() - _, err := runProgramAction( + if _, err := runProgramAction( pme, nil, // sketch "", // importFile @@ -54,8 +53,7 @@ func BurnBootloader(ctx context.Context, req *rpc.BurnBootloaderRequest, outStre errStream, req.GetDryRun(), map[string]string{}, // User fields - ) - if err != nil { + ); err != nil { return nil, err } return &rpc.BurnBootloaderResponse{}, nil diff --git a/commands/upload/programmers_list.go b/commands/upload/programmers_list.go index 7bdeb6b7266..76188ac5e2e 100644 --- a/commands/upload/programmers_list.go +++ b/commands/upload/programmers_list.go @@ -26,9 +26,9 @@ import ( // ListProgrammersAvailableForUpload FIXMEDOC func ListProgrammersAvailableForUpload(ctx context.Context, req *rpc.ListProgrammersAvailableForUploadRequest) (*rpc.ListProgrammersAvailableForUploadResponse, error) { - pme, release := instances.GetPackageManagerExplorer(req.GetInstance()) - if pme == nil { - return nil, &cmderrors.InvalidInstanceError{} + pme, release, err := instances.GetPackageManagerExplorer(req.GetInstance()) + if err != nil { + return nil, err } defer release() diff --git a/commands/upload/upload.go b/commands/upload/upload.go index 0d1e257a09e..34aa397b7c9 100644 --- a/commands/upload/upload.go +++ b/commands/upload/upload.go @@ -49,12 +49,11 @@ func SupportedUserFields(ctx context.Context, req *rpc.SupportedUserFieldsReques return nil, &cmderrors.MissingPortProtocolError{} } - pme, release := instances.GetPackageManagerExplorer(req.GetInstance()) - defer release() - - if pme == nil { - return nil, &cmderrors.InvalidInstanceError{} + pme, release, err := instances.GetPackageManagerExplorer(req.GetInstance()) + if err != nil { + return nil, err } + defer release() fqbn, err := cores.ParseFQBN(req.GetFqbn()) if err != nil { @@ -136,9 +135,9 @@ func Upload(ctx context.Context, req *rpc.UploadRequest, outStream io.Writer, er return nil, &cmderrors.CantOpenSketchError{Cause: err} } - pme, pmeRelease := instances.GetPackageManagerExplorer(req.GetInstance()) - if pme == nil { - return nil, &cmderrors.InvalidInstanceError{} + pme, pmeRelease, err := instances.GetPackageManagerExplorer(req.GetInstance()) + if err != nil { + return nil, err } defer pmeRelease()