Need support for error message while forming a `Node` class object in `Jsonpatch`
Hi, I was working on removing property values from a json for a given JsonPointer using jsonpatch.remove from main branch / jsonpatch.apply_remove from v9.0
example_json = {
"foo": variable
}
json_pointer = JsonPointer("/foo/{}".format(pointer))
Scenarios:
- While forming a
Nodeclass why do we have anassertstatemet. In production all the assert statements will be removed. - When the
variablehas a value ofNoneorintegerand assertion was removed In that case we will be getting an error asAttributeError: Node object has no attribute typein line 256 - Are we considering string as list of characters (Sequence). when the
Variablehas a value ofStringand thepointerhas a integer value less than length of the string we will get a error asTypeError: str object doesn't support item deletionin line 260 - When the
Variablehas a value ofStringand thepointerhas a integer value greater than or equal to the length of the string. we will get error asjschon.exceptions.JSONPatchError: Invalid array index {pointer_value}in line 219
Note:
In all the scenarios listed above we are giving a invalid JsonPointer for removing the value from json. Whether can we get a error response which says Invalid jsonpointer was passed {str(jsonpointer)}
Doubt:
Thanks for raising this issue. I agree with all your points and will look into improving the handling of invalid pointers and other edge cases / ambiguities.
The jsonpatch module in fact has the lowest test coverage (~65%) of all jschon modules, so there's a clear case for more comprehensive testing of the JSON patch functionality, too.