mirror of
https://github.com/vlang/v.git
synced 2025-09-10 07:47:20 -04:00
x.json2: improve error message upon missing comma (#20602)
This commit is contained in:
parent
365bd18542
commit
aeadc0a12a
@ -407,10 +407,10 @@ fn (mut p Parser) decode_object() !Any {
|
|||||||
p.next_with_err()!
|
p.next_with_err()!
|
||||||
// step 3 -> value
|
// step 3 -> value
|
||||||
fields[cur_key] = p.decode_value()!
|
fields[cur_key] = p.decode_value()!
|
||||||
if p.tok.kind != .comma && p.tok.kind != .rcbr {
|
if p.tok.kind !in [.comma, .rcbr] {
|
||||||
return UnknownTokenError{
|
return InvalidTokenError{
|
||||||
token: p.tok
|
token: p.tok
|
||||||
kind: .object
|
expected: .comma
|
||||||
}
|
}
|
||||||
} else if p.tok.kind == .comma {
|
} else if p.tok.kind == .comma {
|
||||||
p.next_with_err()!
|
p.next_with_err()!
|
||||||
|
@ -82,3 +82,29 @@ fn test_raw_decode_array_invalid() {
|
|||||||
}
|
}
|
||||||
assert false
|
assert false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct ContactItem {
|
||||||
|
description string
|
||||||
|
telnr string
|
||||||
|
}
|
||||||
|
|
||||||
|
struct User {
|
||||||
|
name string
|
||||||
|
age int
|
||||||
|
contact ContactItem
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_decode_missing_comma() {
|
||||||
|
data := '{
|
||||||
|
"name": "Frodo",
|
||||||
|
"age": 25
|
||||||
|
"contact": {
|
||||||
|
"description": "descr",
|
||||||
|
"telnr": "+32333"
|
||||||
|
}
|
||||||
|
}'
|
||||||
|
user := json.decode[User](data) or {
|
||||||
|
assert err.msg().contains('invalid token')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user