@@ -38,15 +38,7 @@ import (
38
38
"github.com/sirupsen/logrus"
39
39
)
40
40
41
- type boardNotFoundError struct {}
42
-
43
- func (e * boardNotFoundError ) Error () string {
44
- return tr ("board not found" )
45
- }
46
-
47
41
var (
48
- // ErrNotFound is returned when the API returns 404
49
- ErrNotFound = & boardNotFoundError {}
50
42
vidPidURL = "https://builder.arduino.cc/v3/boards/byVidPid"
51
43
validVidPid = regexp .MustCompile (`0[xX][a-fA-F\d]{4}` )
52
44
)
@@ -59,9 +51,6 @@ func cachedAPIByVidPid(vid, pid string) ([]*rpc.BoardListItem, error) {
59
51
ts := inventory .Store .GetTime (cacheKey + ".ts" )
60
52
if time .Since (ts ) < time .Hour * 24 {
61
53
// Use cached response
62
- if cachedResp == "ErrNotFound" {
63
- return nil , ErrNotFound
64
- }
65
54
if err := json .Unmarshal ([]byte (cachedResp ), & resp ); err == nil {
66
55
return resp , nil
67
56
}
@@ -70,11 +59,7 @@ func cachedAPIByVidPid(vid, pid string) ([]*rpc.BoardListItem, error) {
70
59
71
60
resp , err := apiByVidPid (vid , pid ) // Perform API requrest
72
61
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 {
78
63
if cachedResp , err := json .Marshal (resp ); err == nil {
79
64
inventory .Store .Set (cacheKey + ".data" , string (cachedResp ))
80
65
inventory .Store .Set (cacheKey + ".ts" , time .Now ())
@@ -109,10 +94,11 @@ func apiByVidPid(vid, pid string) ([]*rpc.BoardListItem, error) {
109
94
if err != nil {
110
95
return nil , errors .Wrap (err , tr ("error querying Arduino Cloud Api" ))
111
96
}
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
+ }
112
101
if res .StatusCode >= 400 {
113
- if res .StatusCode == 404 {
114
- return nil , ErrNotFound
115
- }
116
102
return nil , errors .Errorf (tr ("the server responded with status %s" ), res .Status )
117
103
}
118
104
@@ -146,7 +132,7 @@ func identifyViaCloudAPI(port *discovery.Port) ([]*rpc.BoardListItem, error) {
146
132
// If the port is not USB do not try identification via cloud
147
133
id := port .Properties
148
134
if ! id .ContainsKey ("vid" ) || ! id .ContainsKey ("pid" ) {
149
- return nil , ErrNotFound
135
+ return nil , nil
150
136
}
151
137
152
138
logrus .Debug ("Querying builder API for board identification..." )
@@ -181,17 +167,10 @@ func identify(pme *packagemanager.Explorer, port *discovery.Port) ([]*rpc.BoardL
181
167
// the builder API if the board is a USB device port
182
168
if len (boards ) == 0 {
183
169
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 {
188
171
// this is bad, but keep going
189
172
logrus .WithError (err ).Debug ("Error querying builder API" )
190
173
}
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)
195
174
boards = items
196
175
}
197
176
0 commit comments