MCPcopy Index your code
hub / github.com/cockroachdb/errors / formatSingleLineOutput

Method formatSingleLineOutput

errbase/format_error.go:318–345  ·  view source on GitHub ↗

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(

()

Source from the content-addressed store, hash-verified

316// from redact.SafePrinter to do this, so care should be taken below
317// to properly escape markers, etc.
318func (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.

Callers 4

formatErrorInternalFunction · 0.95
formatEntriesMethod · 0.95

Calls 1

WriteMethod · 0.80

Tested by 2