formatEntries reads the entries from s.entries and produces a detailed rendering in s.finalBuf. Note that if s.redactableOutput is true, s.finalBuf is to contain a RedactableBytes. However, we are not using the helper facilities from redact.SafePrinter to do this, so care should be taken below to p
(err error)
| 193 | // from redact.SafePrinter to do this, so care should be taken below |
| 194 | // to properly escape markers, etc. |
| 195 | func (s *state) formatEntries(err error) { |
| 196 | // The first entry at the top is special. We format it as follows: |
| 197 | // |
| 198 | // <complete error message> |
| 199 | // (1) <details> |
| 200 | s.formatSingleLineOutput() |
| 201 | s.finalBuf.WriteString("\n(1)") |
| 202 | |
| 203 | s.printEntry(s.entries[len(s.entries)-1]) |
| 204 | |
| 205 | // All the entries that follow are printed as follows: |
| 206 | // |
| 207 | // Wraps: (N) <details> |
| 208 | // |
| 209 | for i, j := len(s.entries)-2, 2; i >= 0; i, j = i-1, j+1 { |
| 210 | s.finalBuf.WriteByte('\n') |
| 211 | // Extra indentation starts at depth==2 because the direct |
| 212 | // children of the root error area already printed on separate |
| 213 | // newlines. |
| 214 | for m := 0; m < s.entries[i].depth-1; m += 1 { |
| 215 | if m == s.entries[i].depth-2 { |
| 216 | s.finalBuf.WriteString("└─ ") |
| 217 | } else { |
| 218 | s.finalBuf.WriteByte(' ') |
| 219 | s.finalBuf.WriteByte(' ') |
| 220 | } |
| 221 | } |
| 222 | fmt.Fprintf(&s.finalBuf, "Wraps: (%d)", j) |
| 223 | entry := s.entries[i] |
| 224 | s.printEntry(entry) |
| 225 | } |
| 226 | |
| 227 | // At the end, we link all the (N) references to the Go type of the |
| 228 | // error. |
| 229 | s.finalBuf.WriteString("\nError types:") |
| 230 | for i, j := len(s.entries)-1, 1; i >= 0; i, j = i-1, j+1 { |
| 231 | fmt.Fprintf(&s.finalBuf, " (%d) %T", j, s.entries[i].err) |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | // printEntry renders the entry given as argument |
| 236 | // into s.finalBuf. |
no test coverage detected