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 {
// ToRPCStatus converts the error into a *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
......
......@@ -63,5 +63,6 @@ func (s *ArduinoCoreServerImpl) Debug(stream rpc.ArduinoCoreService_DebugServer)
// GetDebugConfig return metadata about a debug session
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
import (
"context"
"errors"
"os"
"github.com/arduino/arduino-cli/arduino"
"github.com/arduino/arduino-cli/commands/upload"
"github.com/arduino/arduino-cli/i18n"
"github.com/arduino/arduino-cli/internal/cli/arguments"
......@@ -82,7 +84,14 @@ func runBootloaderCommand(command *cobra.Command, args []string) {
Programmer: programmer.String(instance, fqbn.String()),
DryRun: dryRun,
}, 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())
}
......@@ -280,7 +280,14 @@ func runCompileCommand(cmd *cobra.Command, args []string) {
}
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 {
uploadRes = res
}
......
......@@ -18,9 +18,11 @@ package debug
import (
"context"
"encoding/json"
"errors"
"os"
"os/signal"
"github.com/arduino/arduino-cli/arduino"
"github.com/arduino/arduino-cli/commands/debug"
"github.com/arduino/arduino-cli/commands/sketch"
"github.com/arduino/arduino-cli/i18n"
......@@ -93,7 +95,11 @@ func runDebugCommand(command *cobra.Command, args []string) {
if printInfo {
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 {
feedback.PrintResult(newDebugInfoResult(res))
}
......@@ -109,7 +115,11 @@ func runDebugCommand(command *cobra.Command, args []string) {
feedback.FatalError(err, feedback.ErrBadArgument)
}
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 (
// ErrBadArgument is returned when the arguments are not valid (7)
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) {
UserFields: fields,
}
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 {
io := stdIOResult()
feedback.PrintResult(&uploadResult{
......
This diff is collapsed.
......@@ -74,6 +74,10 @@ message Programmer {
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 {
// Platform ID (e.g., `arduino:avr`).
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