Skip to content

Commit f27b82b

Browse files
committed
Supports invalid-value error.
1 parent f71d99d commit f27b82b

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

bin/jp.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ def main():
4242
except exceptions.JMESPathTypeError as e:
4343
sys.stderr.write("invalid-type: %s\n" % e)
4444
return 1
45+
except exceptions.JMESPathValueError as e:
46+
sys.stderr.write("invalid-value: %s\n" % e)
47+
return 1
4548
except exceptions.UnknownFunctionError as e:
4649
sys.stderr.write("unknown-function: %s\n" % e)
4750
return 1

jmespath/exceptions.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,21 @@ def __str__(self):
112112
self.expected_types, self.actual_type))
113113

114114

115+
@with_str_method
116+
class JMESPathValueError(JMESPathError):
117+
def __init__(self, function_name, current_value, actual_value,
118+
expected_types):
119+
self.function_name = function_name
120+
self.current_value = current_value
121+
self.actual_value = actual_value
122+
self.expected_types = expected_types
123+
124+
def __str__(self):
125+
return ('In function %s(), invalid value: %s, '
126+
'expected: %s, received: "%s"' % (
127+
self.function_name, self.current_value,
128+
self.expected_types, self.actual_value))
129+
115130
class EmptyExpressionError(JMESPathError):
116131
def __init__(self):
117132
super(EmptyExpressionError, self).__init__(

0 commit comments

Comments
 (0)