Skip to content

Commit ad98866

Browse files
committed
Return non-zero exit code when a task fails
1 parent 02b89b7 commit ad98866

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

cmd/virgo/main.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"errors"
66
"fmt"
7-
"log"
87
"net/url"
98
"os"
109
"path/filepath"
@@ -19,6 +18,7 @@ import (
1918

2019
const URL = "url"
2120

21+
var ErrCmdFailed = errors.New("command failed")
2222
var ErrInvalidDeviceProperties = errors.New("invalid device properties")
2323
var ErrScreenShotFailed = errors.New("screenshot result error")
2424

@@ -113,7 +113,7 @@ func main() {
113113

114114
err := cmd.Run(context.Background(), os.Args)
115115
if err != nil {
116-
log.Fatal(err)
116+
os.Exit(1)
117117
}
118118
}
119119

@@ -161,10 +161,14 @@ func runTask(ctx context.Context, cmd *cli.Command, name string, params map[stri
161161
}
162162

163163
func stdOutCallback(cmd *cli.Command, e *engine.Engine) error {
164+
var anyErr bool
165+
164166
for r := range e.Results() {
165167
var out string
166168

167169
if r.Error != nil {
170+
anyErr = true
171+
168172
logger.Error().Msgf("result error: %v", r.Error)
169173

170174
continue
@@ -194,6 +198,10 @@ func stdOutCallback(cmd *cli.Command, e *engine.Engine) error {
194198
}
195199
}
196200

201+
if anyErr {
202+
return ErrCmdFailed
203+
}
204+
197205
return nil
198206
}
199207

0 commit comments

Comments
 (0)