summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2013-06-19 21:08:03 +0100
committerMichael Williamson <mike@zwobble.org>2013-06-19 21:08:03 +0100
commitbb51ca65feeb8f579c9b630321c0d30133119162 (patch)
treea473d4d21da82f9249df3729e78362287b5ac5ae
parentf75fba3e2f8f6fdb4905636b92338ddb8365c381 (diff)
Raise ValueError if program is invalid
-rw-r--r--jq.pyx3
-rw-r--r--tests/jq_tests.py8
2 files changed, 10 insertions, 1 deletions
diff --git a/jq.pyx b/jq.pyx
index 447eeb1..604363a 100644
--- a/jq.pyx
+++ b/jq.pyx
@@ -67,6 +67,9 @@ def _string_to_strings(char* program, char* input):
# TODO: error if !compiled
cdef int compiled = jq_compile(jq, program)
+ if not compiled:
+ raise ValueError("program was not valid")
+
cdef jv_parser parser
jv_parser_init(&parser)
# TODO: is len a suitable replacement for strlen (unicode)?
diff --git a/tests/jq_tests.py b/tests/jq_tests.py
index 6e9066b..edc6cb4 100644
--- a/tests/jq_tests.py
+++ b/tests/jq_tests.py
@@ -1,4 +1,4 @@
-from nose.tools import istest, assert_equal
+from nose.tools import istest, assert_equal, assert_raises
from jq import jq
@@ -57,3 +57,9 @@ def output_elements_are_separated_by_newlines_when_there_are_multiple_inputs():
"2\n3\n4",
str(jq(".+1").transform_string("1\n2\n3"))
)
+
+
+@istest
+def value_error_is_raised_if_program_is_invalid():
+ # TODO: should raise in just jq()
+ assert_raises(ValueError, lambda: jq("!").transform_string("[1, 2, 3]"))