diff options
| author | Aleksandr Nogikh <nogikh@google.com> | 2024-01-02 15:40:34 +0100 |
|---|---|---|
| committer | Aleksandr Nogikh <nogikh@google.com> | 2024-02-19 11:54:01 +0000 |
| commit | b578f30201a3220d65b16593fe43ad5a5ebe0d64 (patch) | |
| tree | 7edb226c14744cbeb0a455a8c4624ed98d5d7386 /prog | |
| parent | 033d9b88e6a8e1257e1733bb0ae632836f3116b0 (diff) | |
prog: make invalid union field error more explicit
Include the name of the union and list the correct options.
Diffstat (limited to 'prog')
| -rw-r--r-- | prog/encoding.go | 5 | ||||
| -rw-r--r-- | prog/encoding_test.go | 4 |
2 files changed, 6 insertions, 3 deletions
diff --git a/prog/encoding.go b/prog/encoding.go index cd4eef17f..b5d5114ca 100644 --- a/prog/encoding.go +++ b/prog/encoding.go @@ -747,6 +747,7 @@ func (p *parser) parseArgUnion(typ Type, dir Dir) (Arg, error) { var ( optType Type optDir Dir + options []string ) index := -1 for i, field := range t1.Fields { @@ -754,9 +755,11 @@ func (p *parser) parseArgUnion(typ Type, dir Dir) (Arg, error) { optType, index, optDir = field.Type, i, field.Dir(dir) break } + options = append(options, fmt.Sprintf("%q", field.Name)) } if optType == nil { - p.eatExcessive(true, "wrong union option") + p.eatExcessive(true, "wrong option %q of union %q, available options are: %s", + name, typ.Name(), strings.Join(options, ", ")) return typ.DefaultArg(dir), nil } var opt Arg diff --git a/prog/encoding_test.go b/prog/encoding_test.go index e2abacee1..dd0dd8bfe 100644 --- a/prog/encoding_test.go +++ b/prog/encoding_test.go @@ -226,12 +226,12 @@ func TestDeserialize(t *testing.T) { { In: `test$type_confusion1(&(0x7f0000000000)=@unknown)`, Out: `test$type_confusion1(&(0x7f0000000000))`, - StrictErr: "wrong union option", + StrictErr: `wrong option "unknown" of union "type_confusion", available options are: "f1"`, }, { In: `test$type_confusion1(&(0x7f0000000000)=@unknown={0x0, 'abc'}, 0x0)`, Out: `test$type_confusion1(&(0x7f0000000000))`, - StrictErr: "wrong union option", + StrictErr: `wrong option "unknown" of union "type_confusion", available options are: "f1"`, }, { In: `test$excessive_fields1(&(0x7f0000000000)=0x0)`, |
