Skip to content

Commit 45d4fb4

Browse files
authored
fix: change DisallowUnknownFields error from "missing field" to "unknown field" (#1054)
The diagnostic message for DisallowUnknownFields said "missing field", which reads as if the TOML is missing something required. From the user's perspective, the field is unknown to the target struct. Change the message to "unknown field" for consistency with the DisallowUnknownFields API name and to reduce confusion. Fixes #1049
1 parent c171216 commit 45d4fb4

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

strict.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func (s *strict) MissingField(node *unstable.Node) {
6868

6969
s.missing = append(s.missing, unstable.ParserError{
7070
Highlight: s.keyLocation(node),
71-
Message: "missing field",
71+
Message: "unknown field",
7272
Key: s.key.Key(),
7373
})
7474
}

unmarshaler_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ key3 = "value3"
6565
// strict mode: fields in the document are missing in the target struct
6666
// 2| key1 = "value1"
6767
// 3| key2 = "value2"
68-
// | ~~~~ missing field
68+
// | ~~~~ unknown field
6969
// 4| key3 = "value3"
7070
}
7171

@@ -2387,14 +2387,14 @@ key4 = "value4"
23872387
`,
23882388
expected: `2| key1 = "value1"
23892389
3| key2 = "missing2"
2390-
| ~~~~ missing field
2390+
| ~~~~ unknown field
23912391
4| key3 = "missing3"
23922392
5| key4 = "value4"
23932393
---
23942394
2| key1 = "value1"
23952395
3| key2 = "missing2"
23962396
4| key3 = "missing3"
2397-
| ~~~~ missing field
2397+
| ~~~~ unknown field
23982398
5| key4 = "value4"`,
23992399
target: &struct {
24002400
Key1 string
@@ -2405,7 +2405,7 @@ key4 = "value4"
24052405
desc: "multi-part key",
24062406
input: `a.short.key="foo"`,
24072407
expected: `1| a.short.key="foo"
2408-
| ~~~~~~~~~~~ missing field`,
2408+
| ~~~~~~~~~~~ unknown field`,
24092409
},
24102410
{
24112411
desc: "missing table",

0 commit comments

Comments
 (0)