Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5332ffd

Browse files
authored
Fix regression: do not crash on board list if a discovery is not properly installed (#1814)
* Added tests for #1669 * Fixed regession in discoveries startup Fix #1669
1 parent 436f0bb commit 5332ffd

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

‎arduino/discovery/discovery.go‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -247,29 +247,32 @@ func (disc *PluggableDiscovery) runProcess() error {
247247
return err
248248
}
249249
disc.outgoingCommandsPipe = stdin
250-
disc.process = proc
251250

252251
messageChan := make(chan *discoveryMessage)
253252
disc.incomingMessagesChan = messageChan
254253
go disc.jsonDecodeLoop(stdout, messageChan)
255254

256-
if err := disc.process.Start(); err != nil {
255+
if err := proc.Start(); err != nil {
257256
return err
258257
}
258+
259259
disc.statusMutex.Lock()
260260
defer disc.statusMutex.Unlock()
261+
disc.process = proc
261262
disc.state = Alive
262263
logrus.Infof("started discovery %s process", disc.id)
263264
return nil
264265
}
265266

266267
func (disc *PluggableDiscovery) killProcess() error {
267268
logrus.Infof("killing discovery %s process", disc.id)
268-
if err := disc.process.Kill(); err != nil {
269-
return err
270-
}
271-
if err := disc.process.Wait(); err != nil {
272-
return err
269+
if disc.process != nil {
270+
if err := disc.process.Kill(); err != nil {
271+
return err
272+
}
273+
if err := disc.process.Wait(); err != nil {
274+
return err
275+
}
273276
}
274277
disc.statusMutex.Lock()
275278
defer disc.statusMutex.Unlock()

‎test/test_board.py‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
# a commercial license, send an email to license@arduino.cc.
1515
from pathlib import Path
1616
from git import Repo
17+
import os
18+
import glob
1719
import simplejson as json
1820
import semver
1921
import pytest
@@ -405,6 +407,23 @@ def test_board_list(run_command):
405407
assert "protocol_label" in port["port"]
406408

407409

410+
def test_board_list_with_invalid_discovery(run_command, data_dir):
411+
run_command(["core", "update-index"])
412+
result = run_command(["board", "list"])
413+
assert result.ok
414+
415+
# check that the CLI do no crash if an invalid discovery is installed
416+
# (for example if the installation fails midway).
417+
# https://github.com/arduino/arduino-cli/issues/1669
418+
tool_dir = os.path.join(data_dir, "packages", "builtin", "tools", "serial-discovery")
419+
for file_to_delete in glob.glob(tool_dir + "/*/*"):
420+
os.remove(file_to_delete)
421+
422+
result = run_command(["board", "list"])
423+
assert result.ok
424+
assert "builtin:serial-discovery" in result.stderr
425+
426+
408427
def test_board_listall(run_command):
409428
assert run_command(["update"])
410429
assert run_command(["core", "install", "arduino:avr@1.8.3"])

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /