From 49f5e04a4ceec392c71afdd5e17583cb42c320e6 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Thu, 27 Mar 2014 13:49:35 +0000 Subject: Encapsulate captured errors a little more cleanly --- jq.pyx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/jq.pyx b/jq.pyx index 1174df0..45f3e40 100644 --- a/jq.pyx +++ b/jq.pyx @@ -61,8 +61,8 @@ def jq(object program): cdef int compiled = jq_compile(jq, program_bytes) - if len(error_store._errors) > 0: - raise ValueError("\n".join(error_store._errors)) + if error_store.has_errors(): + raise ValueError(error_store.error_string()) if not compiled: raise ValueError("program was not valid") @@ -82,7 +82,13 @@ cdef void store_error(void* store_ptr, jv error): cdef class _ErrorStore(object): cdef object _errors - cdef store_error(self, char* error): + cdef int has_errors(self): + return len(self._errors) + + cdef object error_string(self): + return "\n".join(self._errors) + + cdef void store_error(self, char* error): self._errors.append(error) -- cgit v1.2.3