traceError is a helper function that aides developers debugging failed cli commands. When we pretty print errors, we lose the context in which they came. This function adds the context back. Unfortunately there is no easy way to get the prefix to: "error string: %w", so we do a bit of string manipul
(err error)
| 1510 | // |
| 1511 | //nolint:errorlint |
| 1512 | func traceError(err error) string { |
| 1513 | if uw, ok := err.(interface{ Unwrap() error }); ok { |
| 1514 | var a, b string |
| 1515 | if err != nil { |
| 1516 | a = err.Error() |
| 1517 | } |
| 1518 | if uw != nil { |
| 1519 | uwerr := uw.Unwrap() |
| 1520 | if uwerr != nil { |
| 1521 | b = uwerr.Error() |
| 1522 | } |
| 1523 | } |
| 1524 | c := strings.TrimSuffix(a, b) |
| 1525 | return c |
| 1526 | } |
| 1527 | return err.Error() |
| 1528 | } |
| 1529 | |
| 1530 | // These styles are arbitrary. |
| 1531 | func headLineStyle() pretty.Style { |
no test coverage detected