Skip to content

Commit 495a5f1

Browse files
authored
[skip changelog] Add gRPC status unwrapping in error feedback (#1272)
1 parent e5f4c95 commit 495a5f1

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

Diff for: cli/feedback/feedback.go

+12
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ package feedback
1717

1818
import (
1919
"encoding/json"
20+
"errors"
2021
"fmt"
2122
"io"
2223
"os"
2324

2425
"github.com/sirupsen/logrus"
26+
"google.golang.org/grpc/status"
2527
)
2628

2729
// OutputFormat is used to determine the output format
@@ -102,6 +104,16 @@ func (fb *Feedback) Print(v interface{}) {
102104
// Errorf behaves like fmt.Printf but writes on the error writer and adds a
103105
// newline. It also logs the error.
104106
func (fb *Feedback) Errorf(format string, v ...interface{}) {
107+
// Unbox grpc status errors
108+
for i := range v {
109+
if s, isStatus := v[i].(*status.Status); isStatus {
110+
v[i] = errors.New(s.Message())
111+
} else if err, isErr := v[i].(error); isErr {
112+
if s, isStatus := status.FromError(err); isStatus {
113+
v[i] = errors.New(s.Message())
114+
}
115+
}
116+
}
105117
fb.Error(fmt.Sprintf(format, v...))
106118
}
107119

0 commit comments

Comments
 (0)