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

Function TestAdaptPkgWithStack

errbase/adapters_test.go:148–176  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

146}
147
148func TestAdaptPkgWithStack(t *testing.T) {
149 // The "with stack" wrapper from github.com/pkg/errors cannot be
150 // serialized exactly, however we are happy to preserve this stack
151 // trace.
152 origErr := pkgErr.WithStack(goErr.New("hello"))
153 t.Logf("start err: %# v", pretty.Formatter(origErr))
154
155 tt := testutils.T{T: t}
156 // Show that there is indeed a stack trace.
157 theStack := fmt.Sprintf("%+v", errbase.GetSafeDetails(origErr))
158 tt.Check(strings.Contains(theStack, "adapters_test.go"))
159
160 newErr := network(t, origErr)
161
162 // In any case, the library preserves the error message.
163 tt.CheckEqual(newErr.Error(), origErr.Error())
164
165 // The decoded error does not compare equal, since
166 // we had to change the type to preserve the stack trace.
167 tt.Check(!reflect.DeepEqual(newErr, origErr))
168
169 // However, it does include the stack trace.
170 details := errbase.GetSafeDetails(newErr).SafeDetails
171 tt.Check(len(details) > 0 && strings.Contains(details[0], "adapters_test.go"))
172
173 // Moreover, if we re-encode and re-decode, that will be preserved exactly!
174 newErr2 := network(t, newErr)
175 tt.CheckDeepEqual(newErr2, newErr)
176}
177
178func TestAdaptProtoErrors(t *testing.T) {
179 // If an error type has a proto representation already,

Callers

nothing calls this directly

Calls 6

CheckMethod · 0.95
CheckEqualMethod · 0.95
CheckDeepEqualMethod · 0.95
GetSafeDetailsFunction · 0.92
networkFunction · 0.70
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…