From c90d5213aefafbe60a361398447217fad018a1aa Mon Sep 17 00:00:00 2001 From: Pritesh Bandi Date: Thu, 22 Dec 2022 10:50:29 -0800 Subject: [PATCH] Fix error message (#236) Fix error message: Instead of printing bytes in error message convert them to string. Signed-off-by: Pritesh Bandi --- plugin/plugin.go | 2 +- plugin/plugin_test.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugin/plugin.go b/plugin/plugin.go index 5852479a..18e07bbb 100644 --- a/plugin/plugin.go +++ b/plugin/plugin.go @@ -171,7 +171,7 @@ func run(ctx context.Context, pluginName string, pluginPath string, req proto.Re if jsonErr != nil { return proto.RequestError{ Code: proto.ErrorCodeGeneric, - Err: fmt.Errorf("response is not in JSON format. error: %v stderr: %v", err, stderr)} + Err: fmt.Errorf("response is not in JSON format. error: %v, stderr: %s", err, string(stderr))} } return re } diff --git a/plugin/plugin_test.go b/plugin/plugin_test.go index 194caad7..e1c78d93 100644 --- a/plugin/plugin_test.go +++ b/plugin/plugin_test.go @@ -17,10 +17,10 @@ import ( func TestGetMetadata(t *testing.T) { t.Run("plugin error is in invalid json format", func(t *testing.T) { exitErr := errors.New("unknown error") - stderr := []byte("{}") + stderr := []byte("sad") wantErr := proto.RequestError{ Code: proto.ErrorCodeGeneric, - Err: fmt.Errorf("response is not in JSON format. error: %v stderr: %v", exitErr, stderr)} + Err: fmt.Errorf("response is not in JSON format. error: %v, stderr: %s", exitErr, string(stderr))} plugin := CLIPlugin{} executor = testCommander{stdout: nil, stderr: stderr, err: exitErr} _, err := plugin.GetMetadata(context.Background(), &proto.GetMetadataRequest{}) @@ -47,7 +47,7 @@ func TestGetMetadata(t *testing.T) { stderr := []byte("") wantErr := proto.RequestError{ Code: proto.ErrorCodeGeneric, - Err: fmt.Errorf("response is not in JSON format. error: %v stderr: %v", exitErr, stderr)} + Err: fmt.Errorf("response is not in JSON format. error: %v, stderr: %s", exitErr, string(stderr))} plugin := CLIPlugin{} executor = testCommander{stdout: nil, stderr: stderr, err: exitErr} _, err := plugin.GetMetadata(context.Background(), &proto.GetMetadataRequest{})