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

Method printEntry

errbase/format_error.go:246–296  ·  view source on GitHub ↗

printEntry renders the entry given as argument into s.finalBuf. If s.redactableOutput is set, then s.finalBuf is to contain a RedactableBytes, with redaction markers. In that case, we must be careful to escape (or not) the entry depending on entry.redactable. If s.redactableOutput is unset, then w

(entry formatEntry)

Source from the content-addressed store, hash-verified

244// redactability. In that case entry.redactable is not set
245// anyway and we can pass contents through.
246func (s *state) printEntry(entry formatEntry) {
247 if len(entry.head) > 0 {
248 if entry.head[0] != '\n' {
249 s.finalBuf.WriteByte(' ')
250 }
251 if len(entry.head) > 0 {
252 if !s.redactableOutput || entry.redactable {
253 // If we don't care about redaction, then we can pass the string
254 // through.
255 //
256 // If we do care about redaction, and entry.redactable is true,
257 // then entry.head is already a RedactableBytes. Then we can
258 // also pass it through.
259 s.finalBuf.Write(entry.head)
260 } else {
261 // We care about redaction, and the head is unsafe. Escape it
262 // and enclose the result within redaction markers.
263 s.finalBuf.Write([]byte(redact.EscapeBytes(entry.head)))
264 }
265 }
266 }
267 if len(entry.details) > 0 {
268 if len(entry.head) == 0 {
269 if entry.details[0] != '\n' {
270 s.finalBuf.WriteByte(' ')
271 }
272 }
273 if !s.redactableOutput || entry.redactable {
274 // If we don't care about redaction, then we can pass the string
275 // through.
276 //
277 // If we do care about redaction, and entry.redactable is true,
278 // then entry.details is already a RedactableBytes. Then we can
279 // also pass it through.
280 s.finalBuf.Write(entry.details)
281 } else {
282 // We care about redaction, and the details are unsafe. Escape
283 // them and enclose the result within redaction markers.
284 s.finalBuf.Write([]byte(redact.EscapeBytes(entry.details)))
285 }
286 }
287 if entry.stackTrace != nil {
288 s.finalBuf.WriteString("\n -- stack trace:")
289 s.finalBuf.WriteString(strings.ReplaceAll(
290 fmt.Sprintf("%+v", entry.stackTrace),
291 "\n", string(detailSep)))
292 if entry.elidedStackTrace {
293 fmt.Fprintf(&s.finalBuf, "%s[...repeated from below...]", detailSep)
294 }
295 }
296}
297
298// formatSingleLineOutput prints the details extracted via
299// formatRecursive() through the chain of errors as if .Error() has

Callers 3

TestPrintEntryFunction · 0.95
TestPrintEntryRedactableFunction · 0.95
formatEntriesMethod · 0.95

Calls 1

WriteMethod · 0.80

Tested by 2

TestPrintEntryFunction · 0.76
TestPrintEntryRedactableFunction · 0.76