github.com/pf-qiu/concourse/v6@v6.7.3-0.20201207032516-1f455d73275f/atc/exec/try_step.go (about) 1 package exec 2 3 import ( 4 "context" 5 "errors" 6 ) 7 8 // TryStep wraps another step, ignores its errors, and always succeeds. 9 type TryStep struct { 10 step Step 11 aborted bool 12 } 13 14 // Try constructs a TryStep. 15 func Try(step Step) Step { 16 return &TryStep{ 17 step: step, 18 aborted: false, 19 } 20 } 21 22 // Run runs the nested step, and always returns nil, ignoring the nested step's 23 // error. 24 func (ts *TryStep) Run(ctx context.Context, state RunState) (bool, error) { 25 _, err := ts.step.Run(ctx, state) 26 if errors.Is(err, context.Canceled) { 27 // propagate aborts errors, but not timeouts 28 return false, err 29 } 30 31 return true, nil 32 }