OverflowKindOf returns the [OverflowKind] of err, or "" if it isn't an overflow error. If err is already wrapped in a [*ContextOverflowError] with a non-empty Kind, that Kind is returned; otherwise classification runs on the unwrapped error.
(err error)
| 198 | // with a non-empty Kind, that Kind is returned; otherwise classification |
| 199 | // runs on the unwrapped error. |
| 200 | func OverflowKindOf(err error) OverflowKind { |
| 201 | if err == nil { |
| 202 | return "" |
| 203 | } |
| 204 | if coe, ok := errors.AsType[*ContextOverflowError](err); ok { |
| 205 | if coe.Kind != "" { |
| 206 | return coe.Kind |
| 207 | } |
| 208 | // Legacy wrap with no Kind — try classifying the underlying. |
| 209 | if coe.Underlying != nil { |
| 210 | if k := classifyOverflow(coe.Underlying); k != "" { |
| 211 | return k |
| 212 | } |
| 213 | } |
| 214 | return OverflowKindTokens |
| 215 | } |
| 216 | return classifyOverflow(err) |
| 217 | } |
| 218 | |
| 219 | // classifyOverflow inspects err for overflow signals and returns the matching |
| 220 | // [OverflowKind], or "" if err is not an overflow error. |