Skip to content

Commit 4c6f547

Browse files
authored
better exception when unable to fully resolve a jsonpointer on add or replace operations
When a "path" jsonpointer in a add or replace operation points to a non-resolvable inner element, raise a JsonPatchConflict with a clear error message rather than a TypeError with an obscure message
1 parent 0c96a53 commit 4c6f547

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

jsonpatch.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,10 @@ def apply(self, obj):
435435
subobj[part] = value
436436

437437
else:
438-
raise TypeError("invalid document type {0}".format(type(subobj)))
439-
438+
if part is None:
439+
raise TypeError("invalid document type {0}".format(type(subobj)))
440+
else:
441+
raise JsonPatchConflict("unable to fully resolve json pointer {0}, part {1}".format(self.location, part))
440442
return obj
441443

442444
def _on_undo_remove(self, path, key):
@@ -480,7 +482,10 @@ def apply(self, obj):
480482
msg = "can't replace non-existent object '{0}'".format(part)
481483
raise JsonPatchConflict(msg)
482484
else:
483-
raise TypeError("invalid document type {0}".format(type(subobj)))
485+
if part is None:
486+
raise TypeError("invalid document type {0}".format(type(subobj)))
487+
else:
488+
raise JsonPatchConflict("unable to fully resolve json pointer {0}, part {1}".format(self.location, part))
484489

485490
subobj[part] = value
486491
return obj

0 commit comments

Comments
 (0)