Skip to content

Commit 896127c

Browse files
committed
Output in json even in case of error
1 parent b84b666 commit 896127c

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

cli/compile/compile.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,8 @@ func run(cmd *cobra.Command, args []string) {
154154
} else {
155155
compileRes, err = compile.Compile(context.Background(), compileReq, os.Stdout, os.Stderr, verboseCompile)
156156
}
157-
if err != nil {
158-
feedback.Errorf("Error during build: %v", err)
159-
os.Exit(errorcodes.ErrGeneric)
160-
}
161157

162-
if uploadAfterCompile {
158+
if err == nil && uploadAfterCompile {
163159
uploadReq := &rpc.UploadReq{
164160
Instance: inst,
165161
Fqbn: fqbn,
@@ -189,7 +185,12 @@ func run(cmd *cobra.Command, args []string) {
189185
CompileOut: compileOut.String(),
190186
CompileErr: compileErr.String(),
191187
BuilderResult: compileRes,
188+
Success: err == nil,
192189
})
190+
if err != nil && output.OutputFormat != "json" {
191+
feedback.Errorf("Error during build: %v", err)
192+
os.Exit(errorcodes.ErrGeneric)
193+
}
193194
}
194195

195196
// initSketchPath returns the current working directory
@@ -211,6 +212,7 @@ type compileResult struct {
211212
CompileOut string `json:"compiler_out"`
212213
CompileErr string `json:"compiler_err"`
213214
BuilderResult *rpc.CompileResp `json:"builder_result"`
215+
Success bool `json:"success"`
214216
}
215217

216218
func (r *compileResult) Data() interface{} {

commands/compile/compile.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
212212

213213
// if it's a regular build, go on...
214214
if err := builder.RunBuilder(builderCtx); err != nil {
215-
return nil, err
215+
return &rpc.CompileResp{}, err
216216
}
217217

218218
// If the export directory is set we assume you want to export the binaries

0 commit comments

Comments
 (0)