diff --git a/cli/instance/instance.go b/cli/instance/instance.go index 37c0d355323..319f21d52be 100644 --- a/cli/instance/instance.go +++ b/cli/instance/instance.go @@ -80,6 +80,40 @@ func getInitResponse() (*rpc.InitResp, error) { resp.PlatformsIndexErrors = rescanResp.PlatformsIndexErrors } + // Init() succeeded but there were errors loading platform indexes, + // let's rescan and try again + if resp.GetPlatformsIndexErrors() != nil { + + // log each error + for _, err := range resp.GetPlatformsIndexErrors() { + logrus.Errorf("Error loading platform index: %v", err) + } + + // update platform index + _, err := commands.UpdateIndex(context.Background(), + &rpc.UpdateIndexReq{Instance: resp.GetInstance()}, output.ProgressBar()) + if err != nil { + return nil, errors.Wrap(err, "updating the core index") + } + + // rescan + rescanResp, err := commands.Rescan(resp.GetInstance().GetId()) + if err != nil { + return nil, errors.Wrap(err, "during rescan") + } + + // errors persist + if rescanResp.GetPlatformsIndexErrors() != nil { + for _, err := range rescanResp.GetPlatformsIndexErrors() { + logrus.Errorf("Still errors after rescan: %v", err) + } + } + + // succeeded, copy over PlatformsIndexErrors in case errors occurred + // during rescan + resp.PlatformsIndexErrors = rescanResp.PlatformsIndexErrors + } + return resp, nil } diff --git a/test/test_board.py b/test/test_board.py index f97e42122f0..f1e3365b9db 100644 --- a/test/test_board.py +++ b/test/test_board.py @@ -449,5 +449,5 @@ def test_board_details_no_flags(run_command): assert result.ok result = run_command("board details") assert not result.ok - assert "Error getting board details: parsing fqbn: invalid fqbn:" + assert "Error getting board details: parsing fqbn: invalid fqbn:" in result.stderr assert result.stdout == "" diff --git a/test/test_core.py b/test/test_core.py index e476df23883..ffc0ac70b30 100644 --- a/test/test_core.py +++ b/test/test_core.py @@ -99,6 +99,14 @@ def test_core_updateindex_invalid_url(run_command): assert result.failed +def test_core_install_without_updateindex(run_command): + # Missing "core update-index" + # Download samd core pinned to 1.8.6 + result = run_command("core install arduino:samd@1.8.6") + assert result.ok + assert "Updating index: package_index.json downloaded" in result.stdout + + @pytest.mark.skipif( platform.system() == "Windows", reason="core fails with fatal error: bits/c++config.h: No such file or directory", )