Skip to content

Commit 1360bda

Browse files
shabbyrobephilhofer
authored andcommitted
Errors include context information about erroneous field
1 parent f65876d commit 1360bda

File tree

13 files changed

+736
-47
lines changed

13 files changed

+736
-47
lines changed

_generated/convert_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ func TestConvertFromEncodeError(t *testing.T) {
1212
var buf bytes.Buffer
1313
w := msgp.NewWriter(&buf)
1414
err := e.EncodeMsg(w)
15-
if err != errConvertFrom {
16-
t.Fatalf("expected conversion error, found %v", err.Error())
15+
if msgp.Cause(err) != errConvertFrom {
16+
t.Fatalf("expected conversion error, found '%v'", err.Error())
1717
}
1818
}
1919

@@ -30,7 +30,8 @@ func TestConvertToEncodeError(t *testing.T) {
3030

3131
r := msgp.NewReader(&buf)
3232
err = (&out).DecodeMsg(r)
33-
if err != errConvertTo {
33+
34+
if msgp.Cause(err) != errConvertTo {
3435
t.Fatalf("expected conversion error, found %v", err.Error())
3536
}
3637
}
@@ -39,7 +40,7 @@ func TestConvertFromMarshalError(t *testing.T) {
3940
e := ConvertErr{ConvertErrVal(fromFailStr)}
4041
var b []byte
4142
_, err := e.MarshalMsg(b)
42-
if err != errConvertFrom {
43+
if msgp.Cause(err) != errConvertFrom {
4344
t.Fatalf("expected conversion error, found %v", err.Error())
4445
}
4546
}
@@ -53,7 +54,7 @@ func TestConvertToMarshalError(t *testing.T) {
5354
}
5455

5556
_, err = (&out).UnmarshalMsg(b)
56-
if err != errConvertTo {
57+
if msgp.Cause(err) != errConvertTo {
5758
t.Fatalf("expected conversion error, found %v", err.Error())
5859
}
5960
}

_generated/def.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ type Custom struct {
194194
Bts CustomBytes `msg:"bts"`
195195
Mp map[string]*Embedded `msg:"mp"`
196196
Enums []MyEnum `msg:"enums"` // test explicit enum shim
197-
Some FileHandle `msg:file_handle`
197+
Some FileHandle `msg:"file_handle"`
198198
}
199199

200200
type Files []*os.File

_generated/errorwrap.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package _generated
2+
3+
//go:generate msgp
4+
5+
// The leaves of interest in this crazy structs are strings. The test case
6+
// looks for strings in the serialised msgpack and makes them unreadable.
7+
8+
type ErrorCtxMapChild struct {
9+
Val string
10+
}
11+
12+
type ErrorCtxAsMap struct {
13+
Val string
14+
Child *ErrorCtxMapChild
15+
Children []*ErrorCtxMapChild
16+
Map map[string]string
17+
18+
Nest struct {
19+
Val string
20+
Child *ErrorCtxMapChild
21+
Children []*ErrorCtxMapChild
22+
Map map[string]string
23+
24+
Nest struct {
25+
Val string
26+
Child *ErrorCtxMapChild
27+
Children []*ErrorCtxMapChild
28+
Map map[string]string
29+
}
30+
}
31+
}
32+
33+
//msgp:tuple ErrorCtxTupleChild
34+
35+
type ErrorCtxTupleChild struct {
36+
Val string
37+
}
38+
39+
//msgp:tuple ErrorCtxAsTuple
40+
41+
type ErrorCtxAsTuple struct {
42+
Val string
43+
Child *ErrorCtxTupleChild
44+
Children []*ErrorCtxTupleChild
45+
Map map[string]string
46+
47+
Nest struct {
48+
Val string
49+
Child *ErrorCtxTupleChild
50+
Children []*ErrorCtxTupleChild
51+
Map map[string]string
52+
53+
Nest struct {
54+
Val string
55+
Child *ErrorCtxTupleChild
56+
Children []*ErrorCtxTupleChild
57+
Map map[string]string
58+
}
59+
}
60+
}

0 commit comments

Comments
 (0)