Skip to content

Commit

Permalink
Fix crash when loading boards
Browse files Browse the repository at this point in the history
  • Loading branch information
silvanocerza committed Jul 9, 2021
1 parent df2d30e commit 3e43e25
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
9 changes: 3 additions & 6 deletions arduino/cores/packagemanager/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,19 +384,16 @@ func (pm *PackageManager) loadBoards(platform *cores.PlatformRelease) error {
} else {
platform.Menus = properties.NewMap()
}
// This is not a board id so we remove it to correctly
// set all other boards properties
delete(propertiesByBoard, "menu")

if !platform.PluggableDiscoveryAware {
for _, boardProperties := range propertiesByBoard {
convertVidPidIdentificationPropertiesToPluggableDiscovery(boardProperties)
}
}

platform.Menus = propertiesByBoard["menu"]

// This is not a board id so we remove it to correctly
// set all other boards properties
delete(propertiesByBoard, "menu")

skippedBoards := []string{}
for boardID, boardProperties := range propertiesByBoard {
var board *cores.Board
Expand Down
36 changes: 36 additions & 0 deletions test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,3 +712,39 @@ def test_core_with_wrong_custom_board_options_is_loaded(run_command, data_dir):
+ "skipping loading of boards arduino-beta-dev:platform_with_wrong_custom_board_options:nessuno: "
+ "malformed custom board options"
) in res.stderr


def test_core_with_missing_custom_board_options_is_loaded(run_command, data_dir):
test_platform_name = "platform_with_missing_custom_board_options"
platform_install_dir = Path(data_dir, "hardware", "arduino-beta-dev", test_platform_name)
platform_install_dir.mkdir(parents=True)

# Install platform in Sketchbook hardware dir
shutil.copytree(
Path(__file__).parent / "testdata" / test_platform_name, platform_install_dir, dirs_exist_ok=True,
)

assert run_command("update")

res = run_command("core list --format json")
assert res.ok

cores = json.loads(res.stdout)
mapped = {core["id"]: core for core in cores}
assert len(mapped) == 1
# Verifies platform is loaded except excluding board with missing options
assert "arduino-beta-dev:platform_with_missing_custom_board_options" in mapped
boards = {b["fqbn"]: b for b in mapped["arduino-beta-dev:platform_with_missing_custom_board_options"]["boards"]}
assert len(boards) == 1
# Verify board with malformed options is not loaded
assert "arduino-beta-dev:platform_with_missing_custom_board_options:nessuno" not in boards
# Verify other board is loaded
assert "arduino-beta-dev:platform_with_missing_custom_board_options:altra" in boards
# Verify warning is shown to user
assert (
"Error initializing instance: "
+ "loading platform release arduino-beta-dev:platform_with_missing_custom_board_options@4.2.0: "
+ "loading boards: "
+ "skipping loading of boards arduino-beta-dev:platform_with_missing_custom_board_options:nessuno: "
+ "malformed custom board options"
) in res.stderr

0 comments on commit 3e43e25

Please sign in to comment.