Skip to content

Commit aecd25b

Browse files
committed
debug: return error if debugging is not supported by the platform
1 parent 2244af6 commit aecd25b

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

cli/debug/debug.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"github.com/fatih/color"
3434
"github.com/sirupsen/logrus"
3535
"github.com/spf13/cobra"
36+
"google.golang.org/grpc/status"
3637
)
3738

3839
var (
@@ -93,6 +94,10 @@ func run(command *cobra.Command, args []string) {
9394
if printInfo {
9495

9596
if res, err := debug.GetDebugConfig(context.Background(), debugConfigRequested); err != nil {
97+
if status, ok := status.FromError(err); ok {
98+
feedback.Errorf("Error getting Debug info: %v", status.Message())
99+
errorcodes.ExitWithGrpcStatus(status)
100+
}
96101
feedback.Errorf("Error getting Debug info: %v", err)
97102
os.Exit(errorcodes.ErrGeneric)
98103
} else {

cli/errorcodes/errorcodes.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@
1515

1616
package errorcodes
1717

18+
import (
19+
"os"
20+
21+
"google.golang.org/grpc/codes"
22+
"google.golang.org/grpc/status"
23+
)
24+
1825
// Error codes to be used for os.Exit().
1926
const (
2027
_ = iota // 0 is not a valid exit error code
@@ -29,3 +36,14 @@ const (
2936
ErrCoreConfig
3037
ErrBadArgument
3138
)
39+
40+
// ExitWithGrpcStatus will terminate the current process by returing the correct
41+
// error code closest matching the gRPC status.
42+
func ExitWithGrpcStatus(s *status.Status) {
43+
switch s.Code() {
44+
case codes.Unimplemented:
45+
os.Exit(ErrBadArgument)
46+
default:
47+
os.Exit(ErrGeneric)
48+
}
49+
}

commands/debug/debug_info.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import (
2929
"github.com/arduino/go-properties-orderedmap"
3030
"github.com/pkg/errors"
3131
"github.com/sirupsen/logrus"
32+
"google.golang.org/grpc/codes"
33+
"google.golang.org/grpc/status"
3234
)
3335

3436
// GetDebugConfig returns metadata to start debugging with the specified board
@@ -40,6 +42,10 @@ func GetDebugConfig(ctx context.Context, req *debug.DebugConfigReq) (*debug.GetD
4042
return nil, err
4143
}
4244

45+
if !props.ContainsKey("executable") {
46+
return nil, status.Error(codes.Unimplemented, fmt.Sprintf("debugging not supported for board %s", req.GetFqbn()))
47+
}
48+
4349
server := props.Get("server")
4450
toolchain := props.Get("toolchain")
4551
resp := &debug.GetDebugConfigResp{

0 commit comments

Comments
 (0)