Skip to content

Commit

Permalink
Improved assertion error messages on usage of JsonNode iterators on w…
Browse files Browse the repository at this point in the history
…rong kinds (#13389)
  • Loading branch information
zevv committed Feb 17, 2020
1 parent 006fe4c commit 7355362
Showing 1 changed file with 5 additions and 5 deletions.
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

0 comments on commit 7355362

Please sign in to comment.