aboutsummaryrefslogtreecommitdiff
path: root/setuptools/_vendor/_validate_pyproject/fastjsonschema_exceptions.py
diff options
context:
space:
mode:
Diffstat (limited to 'setuptools/_vendor/_validate_pyproject/fastjsonschema_exceptions.py')
-rw-r--r--setuptools/_vendor/_validate_pyproject/fastjsonschema_exceptions.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/setuptools/_vendor/_validate_pyproject/fastjsonschema_exceptions.py b/setuptools/_vendor/_validate_pyproject/fastjsonschema_exceptions.py
new file mode 100644
index 0000000..d2dddd6
--- /dev/null
+++ b/setuptools/_vendor/_validate_pyproject/fastjsonschema_exceptions.py
@@ -0,0 +1,51 @@
+import re
+
+
+SPLIT_RE = re.compile(r'[\.\[\]]+')
+
+
+class JsonSchemaException(ValueError):
+ """
+ Base exception of ``fastjsonschema`` library.
+ """
+
+
+class JsonSchemaValueException(JsonSchemaException):
+ """
+ Exception raised by validation function. Available properties:
+
+ * ``message`` containing human-readable information what is wrong (e.g. ``data.property[index] must be smaller than or equal to 42``),
+ * invalid ``value`` (e.g. ``60``),
+ * ``name`` of a path in the data structure (e.g. ``data.property[index]``),
+ * ``path`` as an array in the data structure (e.g. ``['data', 'property', 'index']``),
+ * the whole ``definition`` which the ``value`` has to fulfil (e.g. ``{'type': 'number', 'maximum': 42}``),
+ * ``rule`` which the ``value`` is breaking (e.g. ``maximum``)
+ * and ``rule_definition`` (e.g. ``42``).
+
+ .. versionchanged:: 2.14.0
+ Added all extra properties.
+ """
+
+ def __init__(self, message, value=None, name=None, definition=None, rule=None):
+ super().__init__(message)
+ self.message = message
+ self.value = value
+ self.name = name
+ self.definition = definition
+ self.rule = rule
+
+ @property
+ def path(self):
+ return [item for item in SPLIT_RE.split(self.name) if item != '']
+
+ @property
+ def rule_definition(self):
+ if not self.rule or not self.definition:
+ return None
+ return self.definition.get(self.rule)
+
+
+class JsonSchemaDefinitionException(JsonSchemaException):
+ """
+ Exception raised by generator of validation function.
+ """