Skip to content

Commit 52499a9

Browse files
committed
Report discovery start errors
1 parent 1be67ef commit 52499a9

File tree

6 files changed

+24
-12
lines changed

6 files changed

+24
-12
lines changed

Diff for: arduino/discovery/discoverymanager/discoverymanager.go

+12-3
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,11 @@ func (dm *DiscoveryManager) IDs() []string {
8181

8282
// Start starts all the discoveries in this DiscoveryManager.
8383
// If the discoveries are already running, this function does nothing.
84-
func (dm *DiscoveryManager) Start() {
84+
func (dm *DiscoveryManager) Start() []error {
8585
dm.discoveriesMutex.Lock()
8686
defer dm.discoveriesMutex.Unlock()
8787
if dm.discoveriesRunning {
88-
return
88+
return nil
8989
}
9090

9191
go func() {
@@ -95,16 +95,25 @@ func (dm *DiscoveryManager) Start() {
9595
}
9696
}()
9797

98+
errs := []error{}
99+
var errsLock sync.Mutex
100+
98101
var wg sync.WaitGroup
99102
for _, d := range dm.discoveries {
100103
wg.Add(1)
101104
go func(d *discovery.PluggableDiscovery) {
102-
dm.startDiscovery(d)
105+
if err := dm.startDiscovery(d); err != nil {
106+
errsLock.Lock()
107+
errs = append(errs, err)
108+
errsLock.Unlock()
109+
}
103110
wg.Done()
104111
}(d)
105112
}
106113
wg.Wait()
107114
dm.discoveriesRunning = true
115+
116+
return errs
108117
}
109118

110119
// Add adds a discovery to the list of managed discoveries

Diff for: cli/arguments/completion.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ func GetInstallableLibs() []string {
178178
func GetConnectedBoards() []string {
179179
inst := instance.CreateAndInit()
180180

181-
list, _ := board.List(&rpc.BoardListRequest{
181+
list, _, _ := board.List(&rpc.BoardListRequest{
182182
Instance: inst,
183183
})
184184
var res []string

Diff for: cli/arguments/port.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ func (p *Port) GetSearchTimeout() time.Duration {
146146
// discovered Port object together with the FQBN. If the port does not match
147147
// exactly 1 board,
148148
func (p *Port) DetectFQBN(inst *rpc.Instance) (string, *rpc.Port) {
149-
detectedPorts, err := board.List(&rpc.BoardListRequest{
149+
detectedPorts, _, err := board.List(&rpc.BoardListRequest{
150150
Instance: inst,
151151
Timeout: p.timeout.Get().Milliseconds(),
152152
})

Diff for: cli/board/list.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,16 @@ func runListCommand(cmd *cobra.Command, args []string) {
6464
os.Exit(0)
6565
}
6666

67-
ports, err := board.List(&rpc.BoardListRequest{
67+
ports, discvoeryErrors, err := board.List(&rpc.BoardListRequest{
6868
Instance: inst,
6969
Timeout: timeoutArg.Get().Milliseconds(),
7070
})
7171
if err != nil {
7272
feedback.Errorf(tr("Error detecting boards: %v"), err)
7373
}
74+
for _, err := range discvoeryErrors {
75+
feedback.Errorf(tr("Error starting discovery: %v"), err)
76+
}
7477
feedback.PrintResult(result{ports})
7578
}
7679

Diff for: commands/board/list.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -177,21 +177,21 @@ func identify(pm *packagemanager.PackageManager, port *discovery.Port) ([]*rpc.B
177177
// List returns a list of boards found by the loaded discoveries.
178178
// In case of errors partial results from discoveries that didn't fail
179179
// are returned.
180-
func List(req *rpc.BoardListRequest) (r []*rpc.DetectedPort, e error) {
180+
func List(req *rpc.BoardListRequest) (r []*rpc.DetectedPort, discoveryStartErrors []error, e error) {
181181
pm := commands.GetPackageManager(req.GetInstance().Id)
182182
if pm == nil {
183-
return nil, &arduino.InvalidInstanceError{}
183+
return nil, nil, &arduino.InvalidInstanceError{}
184184
}
185185

186186
dm := pm.DiscoveryManager()
187-
dm.Start()
187+
discoveryStartErrors = dm.Start()
188188
time.Sleep(time.Duration(req.GetTimeout()) * time.Millisecond)
189189

190190
retVal := []*rpc.DetectedPort{}
191191
for _, port := range dm.List() {
192192
boards, err := identify(pm, port)
193193
if err != nil {
194-
return nil, err
194+
return nil, discoveryStartErrors, err
195195
}
196196

197197
// boards slice can be empty at this point if neither the cores nor the
@@ -202,7 +202,7 @@ func List(req *rpc.BoardListRequest) (r []*rpc.DetectedPort, e error) {
202202
}
203203
retVal = append(retVal, b)
204204
}
205-
return retVal, nil
205+
return retVal, discoveryStartErrors, nil
206206
}
207207

208208
// Watch returns a channel that receives boards connection and disconnection events.

Diff for: commands/daemon/daemon.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func (s *ArduinoCoreServerImpl) BoardDetails(ctx context.Context, req *rpc.Board
6767

6868
// BoardList FIXMEDOC
6969
func (s *ArduinoCoreServerImpl) BoardList(ctx context.Context, req *rpc.BoardListRequest) (*rpc.BoardListResponse, error) {
70-
ports, err := board.List(req)
70+
ports, _, err := board.List(req)
7171
if err != nil {
7272
return nil, convertErrorToRPCStatus(err)
7373
}

0 commit comments

Comments
 (0)