@@ -18,12 +18,12 @@ package arguments
18
18
import (
19
19
"context"
20
20
"errors"
21
+ "fmt"
21
22
"time"
22
23
23
24
"github.com/arduino/arduino-cli/commands"
24
25
"github.com/arduino/arduino-cli/commands/cmderrors"
25
26
f "github.com/arduino/arduino-cli/internal/algorithms"
26
- "github.com/arduino/arduino-cli/internal/cli/feedback"
27
27
"github.com/arduino/arduino-cli/internal/i18n"
28
28
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
29
29
"github.com/sirupsen/logrus"
@@ -132,13 +132,13 @@ func (p *Port) GetSearchTimeout() time.Duration {
132
132
// DetectFQBN tries to identify the board connected to the port and returns the
133
133
// discovered Port object together with the FQBN. If the port does not match
134
134
// exactly 1 board,
135
- func (p * Port ) DetectFQBN (ctx context.Context , inst * rpc.Instance , srv rpc.ArduinoCoreServiceServer ) (string , * rpc.Port ) {
135
+ func (p * Port ) DetectFQBN (ctx context.Context , inst * rpc.Instance , srv rpc.ArduinoCoreServiceServer ) (string , * rpc.Port , error ) {
136
136
detectedPorts , err := srv .BoardList (ctx , & rpc.BoardListRequest {
137
137
Instance : inst ,
138
138
Timeout : p .timeout .Get ().Milliseconds (),
139
139
})
140
140
if err != nil {
141
- feedback . Fatal ( i18n .Tr ("Error during FQBN detection: %v" , err ), feedback . ErrGeneric )
141
+ return "" , nil , fmt . Errorf ( "%s: %w" , i18n .Tr ("Error during board detection" ), err )
142
142
}
143
143
for _ , detectedPort := range detectedPorts .GetPorts () {
144
144
port := detectedPort .GetPort ()
@@ -149,14 +149,14 @@ func (p *Port) DetectFQBN(ctx context.Context, inst *rpc.Instance, srv rpc.Ardui
149
149
continue
150
150
}
151
151
if len (detectedPort .GetMatchingBoards ()) > 1 {
152
- feedback . FatalError ( & cmderrors.MultipleBoardsDetectedError {Port : port }, feedback . ErrBadArgument )
152
+ return "" , nil , & cmderrors.MultipleBoardsDetectedError {Port : port }
153
153
}
154
154
if len (detectedPort .GetMatchingBoards ()) == 0 {
155
- feedback . FatalError ( & cmderrors.NoBoardsDetectedError {Port : port }, feedback . ErrBadArgument )
155
+ return "" , nil , & cmderrors.NoBoardsDetectedError {Port : port }
156
156
}
157
- return detectedPort .GetMatchingBoards ()[0 ].GetFqbn (), port
157
+ return detectedPort .GetMatchingBoards ()[0 ].GetFqbn (), port , nil
158
158
}
159
- return "" , nil
159
+ return "" , nil , & cmderrors. NoBoardsDetectedError { Port : & rpc. Port { Address : p . address , Protocol : p . protocol }}
160
160
}
161
161
162
162
// IsPortFlagSet returns true if the port address is provided
0 commit comments