Skip to content

Commit 02504c5

Browse files
committed
fix empty json
Signed-off-by: Patrik Cyvoct <[email protected]>
1 parent b088051 commit 02504c5

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

internal/core/bootstrap_test.go

+20
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,25 @@ func TestInterruptError(t *testing.T) {
6464
TestCheckStderrGolden(),
6565
),
6666
}))
67+
t.Run("emtpy-error-json", Test(&TestConfig{
68+
Commands: NewCommands(
69+
&Command{
70+
Namespace: "test",
71+
Resource: "empty",
72+
Verb: "error",
73+
ArgsType: reflect.TypeOf(args.RawArgs{}),
74+
Run: func(ctx context.Context, argsI interface{}) (i interface{}, e error) {
75+
return nil, &CliError{Code: 99, Empty: true}
76+
},
77+
},
78+
),
79+
UseE2EClient: true,
80+
DisableParallel: true, // because e2e client is used
81+
Cmd: "scw -o json test empty error",
82+
Check: TestCheckCombine(
83+
TestCheckExitCode(99),
84+
TestCheckStderrGolden(),
85+
),
86+
}))
6787

6888
}

internal/core/error.go

+4
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ func (s *CliError) MarshalHuman() (string, error) {
7272
}
7373

7474
func (s *CliError) MarshalJSON() ([]byte, error) {
75+
if s.Empty {
76+
type emptyRes struct{}
77+
return json.Marshal(&emptyRes{})
78+
}
7579
type tmpRes struct {
7680
Message string `json:"message"`
7781
Error error `json:"error"`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

0 commit comments

Comments
 (0)