diff options
author | Stefan Kögl <stefan@skoegl.net> | 2018-08-01 21:43:09 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-01 21:43:09 +0200 |
commit | 2990bb3d686c09a1550083336365e99247297711 (patch) | |
tree | 40f1b6d90fc24dced15a8773abb6f4e6ead3cfb5 /jsonpatch.py | |
parent | 0c96a53bb3495772193fd98ff18a0ded10128be3 (diff) | |
parent | 4c6f54747176717978f8798057e342d3f672f149 (diff) | |
download | python-json-patch-2990bb3d686c09a1550083336365e99247297711.tar.gz |
Merge pull request #89 from guillp/patch-1
better exception when a 'path' points to a non existing location
Diffstat (limited to 'jsonpatch.py')
-rw-r--r-- | jsonpatch.py | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/jsonpatch.py b/jsonpatch.py index 326608e..4f8a02b 100644 --- a/jsonpatch.py +++ b/jsonpatch.py @@ -435,8 +435,10 @@ class AddOperation(PatchOperation): subobj[part] = value else: - raise TypeError("invalid document type {0}".format(type(subobj))) - + if part is None: + raise TypeError("invalid document type {0}".format(type(subobj))) + else: + raise JsonPatchConflict("unable to fully resolve json pointer {0}, part {1}".format(self.location, part)) return obj def _on_undo_remove(self, path, key): @@ -480,7 +482,10 @@ class ReplaceOperation(PatchOperation): msg = "can't replace non-existent object '{0}'".format(part) raise JsonPatchConflict(msg) else: - raise TypeError("invalid document type {0}".format(type(subobj))) + if part is None: + raise TypeError("invalid document type {0}".format(type(subobj))) + else: + raise JsonPatchConflict("unable to fully resolve json pointer {0}, part {1}".format(self.location, part)) subobj[part] = value return obj |