From e92d00be8d8739185a4913763b9207c12fe2cb19 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 18 Oct 2019 11:36:11 +0200 Subject: [PATCH] Do not bail out if invalid PID is detected during board listing The USB PID, in theory, should be always filled with a value, but for some reason the serial library is not detecting it correctly. This should fix a fatal error on MacOSX, for some devices the returned PID is empty: $ lsusb 2019-10-18 09:47:32.186 system_profiler[34964:3584353] SPUSBDevice: IOCreatePlugInInterfaceForService failed 0xe00002be Bus 020 Device 000: ID 05ac:8600 Apple Inc. Apple T1 Controller Bus 000 Device 001: ID 1d6b:ISPT Linux Foundation USB 3.0 Bus Bus 000 Device 001: ID 1d6b:CIAR Linux Foundation USB 3.1 Bus Bus 001 Device 001: ID 1d6b:CIAR Linux Foundation USB 3.1 Bus This fix should increase robustness until the underlying bug is fixed. --- commands/board/list.go | 12 ++++++------ go.mod | 1 - 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/commands/board/list.go b/commands/board/list.go index 577aa478b6c..1f8bf48b89b 100644 --- a/commands/board/list.go +++ b/commands/board/list.go @@ -35,6 +35,9 @@ import ( var ( // ErrNotFound is returned when the API returns 404 ErrNotFound = errors.New("board not found") + // ErrInvalidParams is returned when invalid VID or PID are passed to the API + ErrInvalidParams = errors.New("Invalid VID/PID parameters") + m sync.Mutex vidPidURL = "https://builder.arduino.cc/v3/boards/byVidPid" validVidPid = regexp.MustCompile(`0[xX][a-fA-F\d]{4}`) @@ -42,11 +45,8 @@ var ( func apiByVidPid(vid, pid string) ([]*rpc.BoardListItem, error) { // ensure vid and pid are valid before hitting the API - if !validVidPid.MatchString(vid) { - return nil, errors.Errorf("Invalid vid value: '%s'", vid) - } - if !validVidPid.MatchString(pid) { - return nil, errors.Errorf("Invalid pid value: '%s'", pid) + if !validVidPid.MatchString(vid) || !validVidPid.MatchString(pid) { + return nil, ErrInvalidParams } url := fmt.Sprintf("%s/%s/%s", vidPidURL, vid, pid) @@ -126,7 +126,7 @@ func List(instanceID int32) ([]*rpc.DetectedPort, error) { port.IdentificationPrefs.Get("vid"), port.IdentificationPrefs.Get("pid"), ) - if err == ErrNotFound { + if err == ErrNotFound || err == ErrInvalidParams { // the board couldn't be detected, print a warning logrus.Debug("Board not recognized") } else if err != nil { diff --git a/go.mod b/go.mod index 8427598d575..b0ae9aa7f2e 100644 --- a/go.mod +++ b/go.mod @@ -43,7 +43,6 @@ require ( go.bug.st/serial.v1 v0.0.0-20180827123349-5f7892a7bb45 golang.org/x/net v0.0.0-20190311183353-d8887717615a golang.org/x/text v0.3.0 - google.golang.org/appengine v1.4.0 // indirect google.golang.org/genproto v0.0.0-20190327125643-d831d65fe17d // indirect google.golang.org/grpc v1.21.1 gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce // indirect