Skip to content

Fix panic calling compile with wrong FQBN #1645

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions commands/compile/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,10 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
PlatformArchitecture: fqbn.PlatformArch,
})
if targetPlatform == nil || pm.GetInstalledPlatformRelease(targetPlatform) == nil {
// TODO: Move this error message in `cli` module
// errorMessage := fmt.Sprintf(
// "\"%[1]s:%[2]s\" platform is not installed, please install it by running \""+
// version.GetAppName()+" core install %[1]s:%[2]s\".", fqbn.Package, fqbn.PlatformArch)
// feedback.Error(errorMessage)
return nil, &arduino.PlatformNotFoundError{Platform: targetPlatform.String(), Cause: fmt.Errorf(tr("platform not installed"))}
return nil, &arduino.PlatformNotFoundError{
Platform: fmt.Sprintf("%s:%s", fqbn.Package, fqbn.PlatformArch),
Cause: fmt.Errorf(tr("platform not installed")),
}
}

builderCtx := &types.Context{}
Expand Down
19 changes: 19 additions & 0 deletions test/test_compile_part_4.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,3 +378,22 @@ def test_compile_without_upload_and_fqbn(run_command, data_dir):
res = run_command(["compile", sketch_path])
assert res.failed
assert "Error during build: Missing FQBN (Fully Qualified Board Name)" in res.stderr


def test_compile_non_installed_platform_with_wrong_packager_and_arch(run_command, data_dir):
assert run_command(["update"])

# Create a sketch
sketch_name = "SketchSimple"
sketch_path = Path(data_dir, sketch_name)
assert run_command(["sketch", "new", sketch_path])

# Compile with wrong packager
res = run_command(["compile", "-b", "wrong:avr:uno", sketch_path])
assert res.failed
assert "Error during build: Platform 'wrong:avr' not found: platform not installed" in res.stderr

# Compile with wrong arch
res = run_command(["compile", "-b", "arduino:wrong:uno", sketch_path])
assert res.failed
assert "Error during build: Platform 'arduino:wrong' not found: platform not installed" in res.stderr