diff --git a/cli/cli_test.go b/cli/cli_test.go index 0a8ed8a7087..c0e1b2c86ad 100644 --- a/cli/cli_test.go +++ b/cli/cli_test.go @@ -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) diff --git a/cli/compile/compile.go b/cli/compile/compile.go index 2ec11914a8c..040aed8c774 100644 --- a/cli/compile/compile.go +++ b/cli/compile/compile.go @@ -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" @@ -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, diff --git a/cli/upload/upload.go b/cli/upload/upload.go index c9b2300b665..14b9b3122a2 100644 --- a/cli/upload/upload.go +++ b/cli/upload/upload.go @@ -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" @@ -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(),
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: