ErrorClass returns the type of the first informative error of the chain, skipping the anonymous wrappers created by fmt.Errorf. It never returns an error message, which could contain user data.
(err error)
| 312 | // skipping the anonymous wrappers created by fmt.Errorf. It never returns an |
| 313 | // error message, which could contain user data. |
| 314 | func ErrorClass(err error) string { |
| 315 | for err != nil { |
| 316 | class := fmt.Sprintf("%T", err) |
| 317 | switch class { |
| 318 | case "*fmt.wrapError", "*fmt.wrapErrors", "*errors.joinError": |
| 319 | if unwrapped := errors.Unwrap(err); unwrapped != nil { |
| 320 | err = unwrapped |
| 321 | continue |
| 322 | } |
| 323 | } |
| 324 | return class |
| 325 | } |
| 326 | return "" |
| 327 | } |