asNonContextError returns err, except if it is context.Canceled or context.DeadlineExceeded in which case the error will be a simple string representation instead. The given context is checked for cancellation, and if it is cancelled then that error is returned instead of err.
(ctx context.Context, err error)
| 213 | // representation instead. The given context is checked for cancellation, |
| 214 | // and if it is cancelled then that error is returned instead of err. |
| 215 | func asNonContextError(ctx context.Context, err error) error { |
| 216 | select { |
| 217 | case <-ctx.Done(): |
| 218 | return ctx.Err() |
| 219 | default: |
| 220 | } |
| 221 | if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) { |
| 222 | return fmt.Errorf("%s (non-context)", err.Error()) |
| 223 | } |
| 224 | return err |
| 225 | } |
| 226 | |
| 227 | func CallWithContext(ctx context.Context, fn func() error) error { |
| 228 | var err error |