Swallow Context Cancel (ARCH5168)
Key go.logging.swallow-context-cancel · Severity warning · Category logging
Swallowing cancellation signals such as context.Canceled or context.DeadlineExceeded breaks shutdown and timeout propagation. These errors should be propagated to the caller, not hidden like an ordinary failure.
Incorrect
Section titled “Incorrect”func run(ctx context.Context) error { if err := work(ctx); err != nil { if errors.Is(err, context.Canceled) { return nil // cancellation swallowed } return err } return nil}Correct
Section titled “Correct”func run(ctx context.Context) error { if err := work(ctx); err != nil { return fmt.Errorf("run: %w", err) } return nil}Propagate cancellation errors to the caller instead of swallowing them, so the shutdown flow works.