Skip to content

Commit 2990bb3

Browse files
authored
Merge pull request #89 from guillp/patch-1
better exception when a 'path' points to a non existing location
2 parents 0c96a53 + 4c6f547 commit 2990bb3

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)