@@ -28,9 +28,10 @@ import (
2828 "github.com/arduino/arduino-cli/arduino/cores/packagemanager"
2929 "github.com/arduino/arduino-cli/arduino/discovery"
3030 "github.com/arduino/arduino-cli/commands"
31+ "github.com/arduino/arduino-cli/errors"
3132 "github.com/arduino/arduino-cli/httpclient"
3233 rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
33- "github.com/pkg/errors"
34+ errs "github.com/pkg/errors"
3435 "github.com/segmentio/stats/v4"
3536 "github.com/sirupsen/logrus"
3637)
@@ -51,10 +52,10 @@ var (
5152func apiByVidPid (vid , pid string ) ([]* rpc.BoardListItem , error ) {
5253 // ensure vid and pid are valid before hitting the API
5354 if ! validVidPid .MatchString (vid ) {
54- return nil , errors .Errorf (tr ("Invalid vid value: '%s'" ), vid )
55+ return nil , fmt .Errorf (tr ("Invalid vid value: '%s'" ), vid )
5556 }
5657 if ! validVidPid .MatchString (pid ) {
57- return nil , errors .Errorf (tr ("Invalid pid value: '%s'" ), pid )
58+ return nil , fmt .Errorf (tr ("Invalid pid value: '%s'" ), pid )
5859 }
5960
6061 url := fmt .Sprintf ("%s/%s/%s" , vidPidURL , vid , pid )
@@ -67,15 +68,15 @@ func apiByVidPid(vid, pid string) ([]*rpc.BoardListItem, error) {
6768 httpClient , err := httpclient .New ()
6869
6970 if err != nil {
70- return nil , errors . Wrap ( err , tr ("failed to initialize http client" ))
71+ return nil , fmt . Errorf ( tr ("failed to initialize http client: %w" , err ))
7172 }
7273
7374 if res , err := httpClient .Do (req ); err == nil {
7475 if res .StatusCode >= 400 {
7576 if res .StatusCode == 404 {
7677 return nil , ErrNotFound
7778 }
78- return nil , errors .Errorf (tr ("the server responded with status %s" ), res .Status )
79+ return nil , fmt .Errorf (tr ("the server responded with status %s" ), res .Status )
7980 }
8081
8182 body , _ := ioutil .ReadAll (res .Body )
@@ -84,22 +85,22 @@ func apiByVidPid(vid, pid string) ([]*rpc.BoardListItem, error) {
8485 var dat map [string ]interface {}
8586 err = json .Unmarshal (body , & dat )
8687 if err != nil {
87- return nil , errors . Wrap ( err , tr ("error processing response from server" ))
88+ return nil , fmt . Errorf ( tr ("error processing response from server: %w" , err ))
8889 }
8990
9091 name , nameFound := dat ["name" ].(string )
9192 fqbn , fbqnFound := dat ["fqbn" ].(string )
9293
9394 if ! nameFound || ! fbqnFound {
94- return nil , errors . New (tr ("wrong format in server response" ))
95+ return nil , fmt . Errorf (tr ("wrong format in server response" ))
9596 }
9697
9798 retVal = append (retVal , & rpc.BoardListItem {
9899 Name : name ,
99100 Fqbn : fqbn ,
100101 })
101102 } else {
102- return nil , errors . Wrap ( err , tr ("error querying Arduino Cloud Api" ))
103+ return nil , fmt . Errorf ( tr ("error querying Arduino Cloud Api: %w" , err ))
103104 }
104105
105106 return retVal , nil
@@ -138,12 +139,12 @@ func identify(pm *packagemanager.PackageManager, port *discovery.Port) ([]*rpc.B
138139 // the builder API if the board is a USB device port
139140 if len (boards ) == 0 {
140141 items , err := identifyViaCloudAPI (port )
141- if errors .Is (err , ErrNotFound ) {
142+ if errs .Is (err , ErrNotFound ) {
142143 // the board couldn't be detected, print a warning
143144 logrus .Debug ("Board not recognized" )
144145 } else if err != nil {
145146 // this is bad, bail out
146- return nil , & commands .UnavailableError {Message : tr ("Error getting board info from Arduino Cloud" )}
147+ return nil , & errors .UnavailableError {Message : tr ("Error getting board info from Arduino Cloud" )}
147148 }
148149
149150 // add a DetectedPort entry in any case: the `Boards` field will
@@ -188,15 +189,15 @@ func List(req *rpc.BoardListRequest) (r []*rpc.DetectedPort, e error) {
188189
189190 pm := commands .GetPackageManager (req .GetInstance ().Id )
190191 if pm == nil {
191- return nil , & commands .InvalidInstanceError {}
192+ return nil , & errors .InvalidInstanceError {}
192193 }
193194
194195 dm := pm .DiscoveryManager ()
195196 if errs := dm .RunAll (); len (errs ) > 0 {
196- return nil , & commands .UnavailableError {Message : tr ("Error starting board discoveries" ), Cause : fmt .Errorf ("%v" , errs )}
197+ return nil , & errors .UnavailableError {Message : tr ("Error starting board discoveries" ), Cause : fmt .Errorf ("%v" , errs )}
197198 }
198199 if errs := dm .StartAll (); len (errs ) > 0 {
199- return nil , & commands .UnavailableError {Message : tr ("Error starting board discoveries" ), Cause : fmt .Errorf ("%v" , errs )}
200+ return nil , & errors .UnavailableError {Message : tr ("Error starting board discoveries" ), Cause : fmt .Errorf ("%v" , errs )}
200201 }
201202 defer func () {
202203 if errs := dm .StopAll (); len (errs ) > 0 {
@@ -208,7 +209,7 @@ func List(req *rpc.BoardListRequest) (r []*rpc.DetectedPort, e error) {
208209 retVal := []* rpc.DetectedPort {}
209210 ports , errs := pm .DiscoveryManager ().List ()
210211 if len (errs ) > 0 {
211- return nil , & commands .UnavailableError {Message : tr ("Error getting board list" ), Cause : fmt .Errorf ("%v" , errs )}
212+ return nil , & errors .UnavailableError {Message : tr ("Error getting board list" ), Cause : fmt .Errorf ("%v" , errs )}
212213 }
213214 for _ , port := range ports {
214215 boards , err := identify (pm , port )
@@ -237,7 +238,7 @@ func Watch(instanceID int32, interrupt <-chan bool) (<-chan *rpc.BoardListWatchR
237238 runErrs := dm .RunAll ()
238239 if len (runErrs ) == len (dm .IDs ()) {
239240 // All discoveries failed to run, we can't do anything
240- return nil , & commands .UnavailableError {Message : tr ("Error starting board discoveries" ), Cause : fmt .Errorf ("%v" , runErrs )}
241+ return nil , & errors .UnavailableError {Message : tr ("Error starting board discoveries" ), Cause : fmt .Errorf ("%v" , runErrs )}
241242 }
242243
243244 eventsChan , errs := dm .StartSyncAll ()
0 commit comments