formatSingleLineOutput prints the details extracted via formatRecursive() through the chain of errors as if .Error() has been called: it only prints the non-detail parts and prints them on one line with ": " separators. This function is used both when FormatError() is called indirectly from .Error(
()
| 316 | // from redact.SafePrinter to do this, so care should be taken below |
| 317 | // to properly escape markers, etc. |
| 318 | func (s *state) formatSingleLineOutput() { |
| 319 | for i := len(s.entries) - 1; i >= 0; i-- { |
| 320 | entry := &s.entries[i] |
| 321 | if entry.elideShort { |
| 322 | continue |
| 323 | } |
| 324 | if s.finalBuf.Len() > 0 && len(entry.head) > 0 { |
| 325 | s.finalBuf.WriteString(": ") |
| 326 | } |
| 327 | if len(entry.head) == 0 { |
| 328 | // shortcut, to avoid the copy below. |
| 329 | continue |
| 330 | } |
| 331 | if !s.redactableOutput || entry.redactable { |
| 332 | // If we don't care about redaction, then we can pass the string |
| 333 | // through. |
| 334 | // |
| 335 | // If we do care about redaction, and entry.redactable is true, |
| 336 | // then entry.head is already a RedactableBytes. Then we can |
| 337 | // also pass it through. |
| 338 | s.finalBuf.Write(entry.head) |
| 339 | } else { |
| 340 | // We do care about redaction, but entry.redactable is unset. |
| 341 | // This means entry.head is unsafe. We need to escape it. |
| 342 | s.finalBuf.Write([]byte(redact.EscapeBytes(entry.head))) |
| 343 | } |
| 344 | } |
| 345 | } |
| 346 | |
| 347 | // formatRecursive performs a post-order traversal on the chain of |
| 348 | // errors to collect error details from innermost to outermost. |