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

Function TestFormatErrorInternal

errbase/format_error_internal_test.go:117–302  ·  view source on GitHub ↗

TestFormatErrorInternal attempts to highlight some idiosyncrasies of the error formatting especially when used with multi-cause error structures. Comments on specific cases below outline some gaps that still require formatting tweaks.

(t *testing.T)

Source from the content-addressed store, hash-verified

115// structures. Comments on specific cases below outline some gaps that
116// still require formatting tweaks.
117func TestFormatErrorInternal(t *testing.T) {
118 tests := []struct {
119 name string
120 err error
121 expectedSimple string
122 expectedVerbose string
123 }{
124 {
125 name: "single wrapper",
126 err: fmt.Errorf("%w", fmt.Errorf("a%w", goErr.New("b"))),
127 expectedSimple: "ab",
128 expectedVerbose: `ab
129(1)
130Wraps: (2) ab
131Wraps: (3) b
132Error types: (1) *fmt.wrapError (2) *fmt.wrapError (3) *errors.errorString`,
133 },
134 {
135 name: "simple multi-wrapper",
136 err: goErr.Join(goErr.New("a"), goErr.New("b")),
137 expectedSimple: "a\nb",
138 // TODO(davidh): verbose test case should have line break
139 // between `a` and `b` on second line.
140 expectedVerbose: `a
141(1) ab
142Wraps: (2) b
143Wraps: (3) a
144Error types: (1) *errors.joinError (2) *errors.errorString (3) *errors.errorString`,
145 },
146 {
147 name: "multi-wrapper with custom formatter and partial elide",
148 err: NewWrapNoElideCauses("A",
149 NewWrapNoElideCauses("C", goErr.New("3"), goErr.New("4")),
150 NewWrapElideCauses("B", goErr.New("1"), goErr.New("2")),
151 ),
152 expectedSimple: `A: B: C: 4: 3`, // 1 and 2 omitted because they are elided.
153 expectedVerbose: `A: B: C: 4: 3
154(1) A
155Wraps: (2) B
156└─ Wraps: (3) 2
157└─ Wraps: (4) 1
158Wraps: (5) C
159└─ Wraps: (6) 4
160└─ Wraps: (7) 3
161Error types: (1) *errbase.wrapNoElideCauses (2) *errbase.wrapElideCauses (3) *errors.errorString (4) *errors.errorString (5) *errbase.wrapNoElideCauses (6) *errors.errorString (7) *errors.errorString`,
162 },
163 {
164 name: "multi-wrapper with custom formatter and no elide",
165 // All errors in this example omit eliding their children.
166 err: NewWrapNoElideCauses("A",
167 NewWrapNoElideCauses("B", goErr.New("1"), goErr.New("2")),
168 NewWrapNoElideCauses("C", goErr.New("3"), goErr.New("4")),
169 ),
170 expectedSimple: `A: C: 4: 3: B: 2: 1`,
171 expectedVerbose: `A: C: 4: 3: B: 2: 1
172(1) A
173Wraps: (2) C
174└─ Wraps: (3) 4

Callers

nothing calls this directly

Calls 4

NewWrapNoElideCausesFunction · 0.85
NewWrapElideCausesFunction · 0.85
RunMethod · 0.80
FormattableFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…