Skip to content

Do not bail out if invalid PID is detected during board listing #447

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 6 additions & 6 deletions commands/board/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@ 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}`)
)

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)
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down