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

Function TestUnknownWrapperTraversalWithMessageOverride

errbase/opaque_test.go:27–58  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

25)
26
27func TestUnknownWrapperTraversalWithMessageOverride(t *testing.T) {
28 // Simulating scenario where the new field on the opaque wrapper is dropped
29 // in the middle of the chain by a node running an older version.
30
31 origErr := fmt.Errorf("this is a wrapped err %w with a non-prefix wrap msg", errors.New("hello"))
32 t.Logf("start err: %# v", pretty.Formatter(origErr))
33
34 // Encode the error, this will use the encoder.
35 enc := EncodeError(context.Background(), origErr)
36 t.Logf("encoded: %# v", pretty.Formatter(enc))
37
38 newErr := DecodeError(context.Background(), enc)
39 t.Logf("decoded: %# v", pretty.Formatter(newErr))
40
41 // simulate node not knowing about `messageType` field
42 newErr.(*opaqueWrapper).messageType = Prefix
43
44 // Encode it again, to simulate the error passed on to another system.
45 enc2 := EncodeError(context.Background(), newErr)
46 t.Logf("encoded2: %# v", pretty.Formatter(enc))
47
48 // Then decode again.
49 newErr2 := DecodeError(context.Background(), enc2)
50 t.Logf("decoded: %# v", pretty.Formatter(newErr2))
51
52 tt := testutils.T{T: t}
53
54 // We expect to see an erroneous `: hello` because our
55 // error passes through a node which drops the new protobuf
56 // field.
57 tt.CheckEqual(newErr2.Error(), origErr.Error()+": hello")
58}

Callers

nothing calls this directly

Calls 4

CheckEqualMethod · 0.95
EncodeErrorFunction · 0.70
DecodeErrorFunction · 0.70
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…