@@ -38,15 +38,7 @@ import (
3838 "github.com/sirupsen/logrus"
3939)
4040
41- type boardNotFoundError struct {}
42-
43- func (e * boardNotFoundError ) Error () string {
44- return tr ("board not found" )
45- }
46-
4741var (
48- // ErrNotFound is returned when the API returns 404
49- ErrNotFound = & boardNotFoundError {}
5042 vidPidURL = "https://builder.arduino.cc/v3/boards/byVidPid"
5143 validVidPid = regexp .MustCompile (`0[xX][a-fA-F\d]{4}` )
5244)
@@ -59,9 +51,6 @@ func cachedAPIByVidPid(vid, pid string) ([]*rpc.BoardListItem, error) {
5951 ts := inventory .Store .GetTime (cacheKey + ".ts" )
6052 if time .Since (ts ) < time .Hour * 24 {
6153 // Use cached response
62- if cachedResp == "ErrNotFound" {
63- return nil , ErrNotFound
64- }
6554 if err := json .Unmarshal ([]byte (cachedResp ), & resp ); err == nil {
6655 return resp , nil
6756 }
@@ -70,11 +59,7 @@ func cachedAPIByVidPid(vid, pid string) ([]*rpc.BoardListItem, error) {
7059
7160 resp , err := apiByVidPid (vid , pid ) // Perform API requrest
7261
73- if err == ErrNotFound {
74- inventory .Store .Set (cacheKey + ".data" , "ErrNotFound" )
75- inventory .Store .Set (cacheKey + ".ts" , time .Now ())
76- inventory .WriteStore ()
77- } else if err == nil {
62+ if err == nil {
7863 if cachedResp , err := json .Marshal (resp ); err == nil {
7964 inventory .Store .Set (cacheKey + ".data" , string (cachedResp ))
8065 inventory .Store .Set (cacheKey + ".ts" , time .Now ())
@@ -109,10 +94,11 @@ func apiByVidPid(vid, pid string) ([]*rpc.BoardListItem, error) {
10994 if err != nil {
11095 return nil , errors .Wrap (err , tr ("error querying Arduino Cloud Api" ))
11196 }
97+ if res .StatusCode == 404 {
98+ // This is not an error, it just means that the board is not recognized
99+ return nil , nil
100+ }
112101 if res .StatusCode >= 400 {
113- if res .StatusCode == 404 {
114- return nil , ErrNotFound
115- }
116102 return nil , errors .Errorf (tr ("the server responded with status %s" ), res .Status )
117103 }
118104
@@ -146,7 +132,7 @@ func identifyViaCloudAPI(port *discovery.Port) ([]*rpc.BoardListItem, error) {
146132 // If the port is not USB do not try identification via cloud
147133 id := port .Properties
148134 if ! id .ContainsKey ("vid" ) || ! id .ContainsKey ("pid" ) {
149- return nil , ErrNotFound
135+ return nil , nil
150136 }
151137
152138 logrus .Debug ("Querying builder API for board identification..." )
@@ -181,17 +167,10 @@ func identify(pme *packagemanager.Explorer, port *discovery.Port) ([]*rpc.BoardL
181167 // the builder API if the board is a USB device port
182168 if len (boards ) == 0 {
183169 items , err := identifyViaCloudAPI (port )
184- if errors .Is (err , ErrNotFound ) {
185- // the board couldn't be detected, print a warning
186- logrus .Debug ("Board not recognized" )
187- } else if err != nil {
170+ if err != nil {
188171 // this is bad, but keep going
189172 logrus .WithError (err ).Debug ("Error querying builder API" )
190173 }
191-
192- // add a DetectedPort entry in any case: the `Boards` field will
193- // be empty but the port will be shown anyways (useful for 3rd party
194- // boards)
195174 boards = items
196175 }
197176
0 commit comments