Skip to content

Commit

Permalink
Improve error message due to missing FQBN in upload/compile commands
Browse files Browse the repository at this point in the history
  • Loading branch information
federicobond committed Jan 8, 2020
1 parent e2bc059 commit 0c3c91a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ func TestCompileCommandsIntegration(t *testing.T) {
// Build sketch without FQBN
exitCode, d = executeWithArgs("compile", sketchPath)
require.NotZero(t, exitCode)
require.Contains(t, string(d), "no FQBN provided")
require.Contains(t, string(d), "Error: no FQBN provided. Set --fqbn flag or attach board to sketch")

// Build sketch for arduino:avr:uno
exitCode, d = executeWithArgs("compile", "-b", "arduino:avr:uno", sketchPath)
Expand Down
11 changes: 11 additions & 0 deletions cli/compile/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
"context"
"os"

"github.com/arduino/arduino-cli/arduino/sketches"

"github.com/arduino/arduino-cli/cli/feedback"

"github.com/arduino/arduino-cli/cli/errorcodes"
Expand Down Expand Up @@ -94,6 +96,15 @@ func run(cmd *cobra.Command, args []string) {
}

sketchPath := initSketchPath(path)
sketch, err := sketches.NewSketchFromPath(sketchPath)
if err != nil {
feedback.Errorf("Error opening sketch: %v", err)
os.Exit(errorcodes.ErrGeneric)
}
if fqbn == "" && sketch.Metadata.CPU.Fqbn == "" {
feedback.Errorf("Error: no FQBN provided. Set --fqbn flag or attach board to sketch")
os.Exit(errorcodes.ErrGeneric)
}

_, err = compile.Compile(context.Background(), &rpc.CompileReq{
Instance: inst,
Expand Down
13 changes: 12 additions & 1 deletion cli/upload/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
"context"
"os"

"github.com/arduino/arduino-cli/arduino/sketches"

"github.com/arduino/arduino-cli/cli/errorcodes"
"github.com/arduino/arduino-cli/cli/feedback"
"github.com/arduino/arduino-cli/cli/instance"
Expand Down Expand Up @@ -71,8 +73,17 @@ func run(command *cobra.Command, args []string) {
path = paths.New(args[0])
}
sketchPath := initSketchPath(path)
sketch, err := sketches.NewSketchFromPath(sketchPath)
if err != nil {
feedback.Errorf("Error opening sketch: %v", err)
os.Exit(errorcodes.ErrGeneric)
}
if fqbn == "" && sketch.Metadata.CPU.Fqbn == "" {
feedback.Errorf("Error: no FQBN provided. Set --fqbn flag or attach board to sketch")
os.Exit(errorcodes.ErrGeneric)
}

if _, err := upload.Upload(context.Background(), &rpc.UploadReq{
if _, err = upload.Upload(context.Background(), &rpc.UploadReq{
Instance: instance,
Fqbn: fqbn,
SketchPath: sketchPath.String(),
Expand Down

0 comments on commit 0c3c91a

Please sign in to comment.