Skip to content

Commit

Permalink
Fix panic calling compile with wrong FQBN (#1645)
Browse files Browse the repository at this point in the history
  • Loading branch information
silvanocerza committed Jan 28, 2022
1 parent 1b0c127 commit 085a31b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
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

0 comments on commit 085a31b

Please sign in to comment.