summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Pujol <guill.p.linux@gmail.com>2018-07-17 17:20:07 +0200
committerGitHub <noreply@github.com>2018-07-17 17:20:07 +0200
commit4c6f54747176717978f8798057e342d3f672f149 (patch)
tree40f1b6d90fc24dced15a8773abb6f4e6ead3cfb5
parent0c96a53bb3495772193fd98ff18a0ded10128be3 (diff)
downloadpython-json-patch-4c6f54747176717978f8798057e342d3f672f149.tar.gz
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
-rw-r--r--jsonpatch.py11
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