| 66 | } |
| 67 | |
| 68 | func (err *TaskfileDecodeError) Debug() string { |
| 69 | const indentWidth = 2 |
| 70 | buf := &bytes.Buffer{} |
| 71 | fmt.Fprintln(buf, "TaskfileDecodeError:") |
| 72 | |
| 73 | // Recursively loop through the error chain and print any details |
| 74 | var debug func(error, int) |
| 75 | debug = func(err error, indent int) { |
| 76 | indentStr := strings.Repeat(" ", indent*indentWidth) |
| 77 | |
| 78 | // Nothing left to unwrap |
| 79 | if err == nil { |
| 80 | fmt.Fprintf(buf, "%sEnd of chain\n", indentStr) |
| 81 | return |
| 82 | } |
| 83 | |
| 84 | // Taskfile decode error |
| 85 | decodeErr := &TaskfileDecodeError{} |
| 86 | if errors.As(err, &decodeErr) { |
| 87 | fmt.Fprintf(buf, "%s%s (%s:%d:%d)\n", |
| 88 | indentStr, |
| 89 | cmp.Or(decodeErr.Message, "<no_message>"), |
| 90 | decodeErr.Location, |
| 91 | decodeErr.Line, |
| 92 | decodeErr.Column, |
| 93 | ) |
| 94 | debug(errors.Unwrap(err), indent+1) |
| 95 | return |
| 96 | } |
| 97 | |
| 98 | fmt.Fprintf(buf, "%s%s\n", indentStr, err) |
| 99 | debug(errors.Unwrap(err), indent+1) |
| 100 | } |
| 101 | debug(err, 0) |
| 102 | return buf.String() |
| 103 | } |
| 104 | |
| 105 | func (err *TaskfileDecodeError) Unwrap() error { |
| 106 | return err.Err |