Commit f85af84d authored by Cristian Maglie's avatar Cristian Maglie

Added specific exit-code for "missing programmer" kind of errors. (#2429)

* Added gRPC message errors

* Implemented specific exit-code for "programmer not found" error
parent 2eba12e9
...@@ -290,7 +290,8 @@ func (e *MissingProgrammerError) Error() string { ...@@ -290,7 +290,8 @@ func (e *MissingProgrammerError) Error() string {
// ToRPCStatus converts the error into a *status.Status // ToRPCStatus converts the error into a *status.Status
func (e *MissingProgrammerError) ToRPCStatus() *status.Status { func (e *MissingProgrammerError) ToRPCStatus() *status.Status {
return status.New(codes.InvalidArgument, e.Error()) s, _ := status.New(codes.InvalidArgument, e.Error()).WithDetails(&rpc.MissingProgrammerError{})
return s
} }
// ProgrammerRequiredForUploadError is returned when the upload can be done only using a programmer // ProgrammerRequiredForUploadError is returned when the upload can be done only using a programmer
......
...@@ -63,5 +63,6 @@ func (s *ArduinoCoreServerImpl) Debug(stream rpc.ArduinoCoreService_DebugServer) ...@@ -63,5 +63,6 @@ func (s *ArduinoCoreServerImpl) Debug(stream rpc.ArduinoCoreService_DebugServer)
// GetDebugConfig return metadata about a debug session // GetDebugConfig return metadata about a debug session
func (s *ArduinoCoreServerImpl) GetDebugConfig(ctx context.Context, req *rpc.GetDebugConfigRequest) (*rpc.GetDebugConfigResponse, error) { func (s *ArduinoCoreServerImpl) GetDebugConfig(ctx context.Context, req *rpc.GetDebugConfigRequest) (*rpc.GetDebugConfigResponse, error) {
return cmd.GetDebugConfig(ctx, req) res, err := cmd.GetDebugConfig(ctx, req)
return res, convertErrorToRPCStatus(err)
} }
...@@ -17,8 +17,10 @@ package burnbootloader ...@@ -17,8 +17,10 @@ package burnbootloader
import ( import (
"context" "context"
"errors"
"os" "os"
"github.com/arduino/arduino-cli/arduino"
"github.com/arduino/arduino-cli/commands/upload" "github.com/arduino/arduino-cli/commands/upload"
"github.com/arduino/arduino-cli/i18n" "github.com/arduino/arduino-cli/i18n"
"github.com/arduino/arduino-cli/internal/cli/arguments" "github.com/arduino/arduino-cli/internal/cli/arguments"
...@@ -82,7 +84,14 @@ func runBootloaderCommand(command *cobra.Command, args []string) { ...@@ -82,7 +84,14 @@ func runBootloaderCommand(command *cobra.Command, args []string) {
Programmer: programmer.String(instance, fqbn.String()), Programmer: programmer.String(instance, fqbn.String()),
DryRun: dryRun, DryRun: dryRun,
}, stdOut, stdErr); err != nil { }, stdOut, stdErr); err != nil {
feedback.Fatal(tr("Error during Upload: %v", err), feedback.ErrGeneric) errcode := feedback.ErrGeneric
if errors.Is(err, &arduino.ProgrammerRequiredForUploadError{}) {
errcode = feedback.ErrMissingProgrammer
}
if errors.Is(err, &arduino.MissingProgrammerError{}) {
errcode = feedback.ErrMissingProgrammer
}
feedback.Fatal(tr("Error during Upload: %v", err), errcode)
} }
feedback.PrintResult(res()) feedback.PrintResult(res())
} }
...@@ -280,7 +280,14 @@ func runCompileCommand(cmd *cobra.Command, args []string) { ...@@ -280,7 +280,14 @@ func runCompileCommand(cmd *cobra.Command, args []string) {
} }
if res, err := upload.Upload(context.Background(), uploadRequest, stdOut, stdErr); err != nil { if res, err := upload.Upload(context.Background(), uploadRequest, stdOut, stdErr); err != nil {
feedback.Fatal(tr("Error during Upload: %v", err), feedback.ErrGeneric) errcode := feedback.ErrGeneric
if errors.Is(err, &arduino.ProgrammerRequiredForUploadError{}) {
errcode = feedback.ErrMissingProgrammer
}
if errors.Is(err, &arduino.MissingProgrammerError{}) {
errcode = feedback.ErrMissingProgrammer
}
feedback.Fatal(tr("Error during Upload: %v", err), errcode)
} else { } else {
uploadRes = res uploadRes = res
} }
......
...@@ -18,9 +18,11 @@ package debug ...@@ -18,9 +18,11 @@ package debug
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"errors"
"os" "os"
"os/signal" "os/signal"
"github.com/arduino/arduino-cli/arduino"
"github.com/arduino/arduino-cli/commands/debug" "github.com/arduino/arduino-cli/commands/debug"
"github.com/arduino/arduino-cli/commands/sketch" "github.com/arduino/arduino-cli/commands/sketch"
"github.com/arduino/arduino-cli/i18n" "github.com/arduino/arduino-cli/i18n"
...@@ -93,7 +95,11 @@ func runDebugCommand(command *cobra.Command, args []string) { ...@@ -93,7 +95,11 @@ func runDebugCommand(command *cobra.Command, args []string) {
if printInfo { if printInfo {
if res, err := debug.GetDebugConfig(context.Background(), debugConfigRequested); err != nil { if res, err := debug.GetDebugConfig(context.Background(), debugConfigRequested); err != nil {
feedback.Fatal(tr("Error getting Debug info: %v", err), feedback.ErrBadArgument) errcode := feedback.ErrBadArgument
if errors.Is(err, &arduino.MissingProgrammerError{}) {
errcode = feedback.ErrMissingProgrammer
}
feedback.Fatal(tr("Error getting Debug info: %v", err), errcode)
} else { } else {
feedback.PrintResult(newDebugInfoResult(res)) feedback.PrintResult(newDebugInfoResult(res))
} }
...@@ -109,7 +115,11 @@ func runDebugCommand(command *cobra.Command, args []string) { ...@@ -109,7 +115,11 @@ func runDebugCommand(command *cobra.Command, args []string) {
feedback.FatalError(err, feedback.ErrBadArgument) feedback.FatalError(err, feedback.ErrBadArgument)
} }
if _, err := debug.Debug(context.Background(), debugConfigRequested, in, out, ctrlc); err != nil { if _, err := debug.Debug(context.Background(), debugConfigRequested, in, out, ctrlc); err != nil {
feedback.Fatal(tr("Error during Debug: %v", err), feedback.ErrGeneric) errcode := feedback.ErrGeneric
if errors.Is(err, &arduino.MissingProgrammerError{}) {
errcode = feedback.ErrMissingProgrammer
}
feedback.Fatal(tr("Error during Debug: %v", err), errcode)
} }
} }
......
...@@ -42,4 +42,18 @@ const ( ...@@ -42,4 +42,18 @@ const (
// ErrBadArgument is returned when the arguments are not valid (7) // ErrBadArgument is returned when the arguments are not valid (7)
ErrBadArgument ErrBadArgument
// ErrFailedToListenToTCPPort is returned if the CLI failed to open a TCP port
// to listen for incoming connections (8)
ErrFailedToListenToTCPPort
// ErrBadTCPPortArgument is returned if the TCP port argument is not valid (9)
ErrBadTCPPortArgument
// ErrInitializingInventory is returned when the inventory cannot be initialized,
// usually depends on a wrong configuration of the data dir (10)
ErrInitializingInventory
// ErrMissingProgrammer is returned when the programmer argument is missing (11)
ErrMissingProgrammer
) )
...@@ -193,7 +193,14 @@ func runUploadCommand(args []string, uploadFieldsArgs map[string]string) { ...@@ -193,7 +193,14 @@ func runUploadCommand(args []string, uploadFieldsArgs map[string]string) {
UserFields: fields, UserFields: fields,
} }
if res, err := upload.Upload(context.Background(), req, stdOut, stdErr); err != nil { if res, err := upload.Upload(context.Background(), req, stdOut, stdErr); err != nil {
feedback.FatalError(err, feedback.ErrGeneric) errcode := feedback.ErrGeneric
if errors.Is(err, &arduino.ProgrammerRequiredForUploadError{}) {
errcode = feedback.ErrMissingProgrammer
}
if errors.Is(err, &arduino.MissingProgrammerError{}) {
errcode = feedback.ErrMissingProgrammer
}
feedback.FatalError(err, errcode)
} else { } else {
io := stdIOResult() io := stdIOResult()
feedback.PrintResult(&uploadResult{ feedback.PrintResult(&uploadResult{
......
This diff is collapsed.
...@@ -74,6 +74,10 @@ message Programmer { ...@@ -74,6 +74,10 @@ message Programmer {
string name = 3; string name = 3;
} }
// MissingProgrammerError is a status error detail that is returned when
// the operation can not be completed due to a missing programmer argument.
message MissingProgrammerError {}
message Platform { message Platform {
// Platform ID (e.g., `arduino:avr`). // Platform ID (e.g., `arduino:avr`).
string id = 1; string id = 1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment