Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved assertion error messages on usage of JsonNode iterators on wrong kinds. #13389

Merged
merged 1 commit into from Feb 17, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/pure/json.nim
Expand Up @@ -739,33 +739,33 @@ proc `$`*(node: JsonNode): string =

iterator items*(node: JsonNode): JsonNode =
## Iterator for the items of `node`. `node` has to be a JArray.
assert node.kind == JArray
assert node.kind == JArray, ": items() can not iterate a JsonNode of kind " & $node.kind
for i in items(node.elems):
yield i

iterator mitems*(node: var JsonNode): var JsonNode =
## Iterator for the items of `node`. `node` has to be a JArray. Items can be
## modified.
assert node.kind == JArray
assert node.kind == JArray, ": mitems() can not iterate a JsonNode of kind " & $node.kind
for i in mitems(node.elems):
yield i

iterator pairs*(node: JsonNode): tuple[key: string, val: JsonNode] =
## Iterator for the child elements of `node`. `node` has to be a JObject.
assert node.kind == JObject
assert node.kind == JObject, ": pairs() can not iterate a JsonNode of kind " & $node.kind
for key, val in pairs(node.fields):
yield (key, val)

iterator keys*(node: JsonNode): string =
## Iterator for the keys in `node`. `node` has to be a JObject.
assert node.kind == JObject
assert node.kind == JObject, ": keys() can not iterate a JsonNode of kind " & $node.kind
for key in node.fields.keys:
yield key

iterator mpairs*(node: var JsonNode): tuple[key: string, val: var JsonNode] =
## Iterator for the child elements of `node`. `node` has to be a JObject.
## Values can be modified
assert node.kind == JObject
assert node.kind == JObject, ": mpairs() can not iterate a JsonNode of kind " & $node.kind
for key, val in mpairs(node.fields):
yield (key, val)

Expand Down