GoogleContainerTools / GoogleContainerTools/skaffold
Revisit `alwaysSucceedWhenCancelled` to succeed if error is context cancelled at all times.
- Dominant language
- Go
- Stars
- 15.9k
- Forks
- 1.7k
- Avg merge
- 3d 9h
- Merged PRs (30d)
- 10
Description
When refactoring code for #5537, I notice `alwaysSucceedWhenCancelled` is a little confusing and returns nil only if `ctx.Err` is cancelled. There are tests in place e.g. [here](https://github.com/GoogleContainerTools/skaffold/blob/788275e8532658a679a8756521b127bfad9f4762/cmd/skaffold/app/cmd/dev_test.go#L97) which rely on this behavior.
This bug is to revisit this and remove the extra check in main.
```
// alwaysSucceedWhenCancelled returns nil if the context was cancelled.
// If the error is due to cancellation, return it as it gets swallowed
// in skaffold main.
// For all other errors, pass through known errors.
// TODO: Return nil if error is `context.Cancelled` and remove check in main.
func alwaysSucceedWhenCancelled(ctx context.Context, runCtx *runcontext.RunContext, err error) error {
if err == nil {
return err
}
// if the context was cancelled act as if all is well
if ctx.Err() == context.Canceled {
return nil
} else if err == context.Canceled {
return err
}
return sErrors.ShowAIError(runCtx, err)
}
```
Contributor guide
Assessment
This issue has not been assessed yet.