Skip to content

Commit

Permalink
Fix handle err of operators on Run/RunN
Browse files Browse the repository at this point in the history
  • Loading branch information
k1LoW committed Sep 15, 2024
1 parent 12fdfe5 commit 436894d
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
)

var errStepSkiped = errors.New("step skipped")
var ErrFailFast = errors.New("fail fast")

var _ otchkiss.Requester = (*operators)(nil)

Expand Down Expand Up @@ -900,7 +901,9 @@ func (o *operator) Run(ctx context.Context) (err error) {
ops.results = append(ops.results, result)
ops.mu.Unlock()
if err != nil {
return err
if !errors.Is(err, ErrFailFast) {
return err
}
}
return result.RunResults[len(result.RunResults)-1].Err
}
Expand Down Expand Up @@ -1521,7 +1524,9 @@ func (ops *operators) RunN(ctx context.Context) (err error) {
ops.results = append(ops.results, result)
ops.mu.Unlock()
if err != nil {
return err
if !errors.Is(err, ErrFailFast) {
return err
}
}
return nil
}
Expand Down Expand Up @@ -1711,7 +1716,7 @@ func (ops *operators) runN(ctx context.Context) (*runNResult, error) {
o.capturers.captureStart(o.trails(), o.bookPath, o.desc)
if err := o.run(cctx); err != nil {
if ops.failFast {
return err
return errors.Join(err, ErrFailFast)
}
}
return nil
Expand Down

0 comments on commit 436894d

Please sign in to comment.