Skip to content

Commit e2c4b89

Browse files
committed
debug: return error if debugging is not supported by the platform
1 parent ee03f7b commit e2c4b89

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-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: 7 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
@@ -150,5 +152,10 @@ func getDebugProperties(req *debug.DebugConfigReq, pm *packagemanager.PackageMan
150152
for k, v := range toolProperties.SubTree("debug").AsMap() {
151153
debugProperties.Set(k, toolProperties.ExpandPropsInString(v))
152154
}
155+
156+
if !debugProperties.ContainsKey("executable") {
157+
return nil, status.Error(codes.Unimplemented, fmt.Sprintf("debugging not supported for board %s", req.GetFqbn()))
158+
}
159+
153160
return debugProperties, nil
154161
}

0 commit comments

Comments
 (0)