MCPcopy
hub / github.com/syncthing/syncthing / asNonContextError

Function asNonContextError

lib/svcutil/svcutil.go:215–225  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

213// representation instead. The given context is checked for cancellation,
214// and if it is cancelled then that error is returned instead of err.
215func 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
227func CallWithContext(ctx context.Context, fn func() error) error {
228 var err error

Callers 1

ServeMethod · 0.85

Calls 3

DoneMethod · 0.80
ErrorMethod · 0.65
IsMethod · 0.45

Tested by

no test coverage detected