context.Cause(ctx) returns the specific error that caused a context to be canceled. Without an explicitly assigned cause, it returns the usual cancellation error. section 10.6.3
Use it when ctx.Err() is ambiguous. A context.WithTimeoutCause call may expire with context.DeadlineExceeded while carrying a more specific application error; context.Cause distinguishes the two. section 10.6.3
Choosing the cancellation diagnostic
When a remote or database operation exceeds its deadline, inspect context.Cause(ctx) rather than ctx.Err() to recover the configured cancellation cause. If no cause was configured, the result remains the usual cancellation error. section 10.6.3
