Skip to content

Commit 3e43e25

Browse files
committed
Fix crash when loading boards
1 parent df2d30e commit 3e43e25

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

Diff for: arduino/cores/packagemanager/loader.go

+3-6
Original file line numberDiff line numberDiff line change
@@ -384,19 +384,16 @@ func (pm *PackageManager) loadBoards(platform *cores.PlatformRelease) error {
384384
} else {
385385
platform.Menus = properties.NewMap()
386386
}
387+
// This is not a board id so we remove it to correctly
388+
// set all other boards properties
389+
delete(propertiesByBoard, "menu")
387390

388391
if !platform.PluggableDiscoveryAware {
389392
for _, boardProperties := range propertiesByBoard {
390393
convertVidPidIdentificationPropertiesToPluggableDiscovery(boardProperties)
391394
}
392395
}
393396

394-
platform.Menus = propertiesByBoard["menu"]
395-
396-
// This is not a board id so we remove it to correctly
397-
// set all other boards properties
398-
delete(propertiesByBoard, "menu")
399-
400397
skippedBoards := []string{}
401398
for boardID, boardProperties := range propertiesByBoard {
402399
var board *cores.Board

Diff for: test/test_core.py

+36
Original file line numberDiff line numberDiff line change
@@ -712,3 +712,39 @@ def test_core_with_wrong_custom_board_options_is_loaded(run_command, data_dir):
712712
+ "skipping loading of boards arduino-beta-dev:platform_with_wrong_custom_board_options:nessuno: "
713713
+ "malformed custom board options"
714714
) in res.stderr
715+
716+
717+
def test_core_with_missing_custom_board_options_is_loaded(run_command, data_dir):
718+
test_platform_name = "platform_with_missing_custom_board_options"
719+
platform_install_dir = Path(data_dir, "hardware", "arduino-beta-dev", test_platform_name)
720+
platform_install_dir.mkdir(parents=True)
721+
722+
# Install platform in Sketchbook hardware dir
723+
shutil.copytree(
724+
Path(__file__).parent / "testdata" / test_platform_name, platform_install_dir, dirs_exist_ok=True,
725+
)
726+
727+
assert run_command("update")
728+
729+
res = run_command("core list --format json")
730+
assert res.ok
731+
732+
cores = json.loads(res.stdout)
733+
mapped = {core["id"]: core for core in cores}
734+
assert len(mapped) == 1
735+
# Verifies platform is loaded except excluding board with missing options
736+
assert "arduino-beta-dev:platform_with_missing_custom_board_options" in mapped
737+
boards = {b["fqbn"]: b for b in mapped["arduino-beta-dev:platform_with_missing_custom_board_options"]["boards"]}
738+
assert len(boards) == 1
739+
# Verify board with malformed options is not loaded
740+
assert "arduino-beta-dev:platform_with_missing_custom_board_options:nessuno" not in boards
741+
# Verify other board is loaded
742+
assert "arduino-beta-dev:platform_with_missing_custom_board_options:altra" in boards
743+
# Verify warning is shown to user
744+
assert (
745+
"Error initializing instance: "
746+
+ "loading platform release arduino-beta-dev:[email protected]: "
747+
+ "loading boards: "
748+
+ "skipping loading of boards arduino-beta-dev:platform_with_missing_custom_board_options:nessuno: "
749+
+ "malformed custom board options"
750+
) in res.stderr

0 commit comments

Comments
 (0)