When implementing error-prone control flow (cleanup helpers, retries/polls, orchestration, allocation paths), do not hide failures.
Coding standard
NotFound), and document that choice.x, _ := mayFail() unless you prove it cannot fail in this context.nil.Example: cleanup helper (return errors, ignore only NotFound)
func deletePodImmediately(ctx context.Context, podClient *e2epod.PodClient, podName string) error {
// Force-delete so namespace teardown doesn't block on intentional container outlives SIGTERM.
err := podClient.Delete(ctx, podName, *metav1.NewDeleteOptions(0))
if apierrors.IsNotFound(err) {
return nil // idempotent: pod already gone
}
return err // non-NotFound failures must fail the spec/caller
}
Example: preserving poll errors (don’t return nil)
for {
ok, err := pollOnce()
if ok {
return true, nil
}
if err != nil {
lastErr = err
// keep retrying until deadline; do not erase lastErr
}
if time.Now().After(deadline) {
return false, lastErr // or deadline error
}
}
Adopting this consistently prevents “silent failure” classes: hidden cleanup regressions, misleading retry outcomes, and far-away error surfacing that makes production incidents much harder to debug.