MCPcopy Index your code
hub / github.com/coder/coder / traceError

Function traceError

cli/root.go:1512–1528  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

1510//
1511//nolint:errorlint
1512func 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.
1531func headLineStyle() pretty.Style {

Callers 1

cliHumanFormatErrorFunction · 0.85

Calls 2

ErrorMethod · 0.45
UnwrapMethod · 0.45

Tested by

no test coverage detected