Skip to content
This repository was archived by the owner on Mar 8, 2018. It is now read-only.

Commit 2ed7c49

Browse files
author
R. Tyler Ballance
committed
Raise a ValuError for bad syntax
1 parent 1a007b6 commit 2ed7c49

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

decoder.c

+6-5
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,8 @@ PyObject *py_yajldecoder_decode(PYARGS)
297297
return NULL;
298298

299299
if (!buflen) {
300-
/* Raise some sort of exception? */
301-
fprintf(stderr, "`buflen` == NULL\n");
300+
PyErr_SetObject(PyExc_ValueError,
301+
PyString_FromString("Cannot parse an empty buffer"));
302302
return NULL;
303303
}
304304

@@ -325,13 +325,14 @@ PyObject *py_yajldecoder_decode(PYARGS)
325325

326326

327327
if (yrc != yajl_status_ok) {
328-
/* Raise some sort of exception */
329-
fprintf(stderr, "FAIL : %s\n", yajl_status_to_string(yrc));
328+
PyErr_SetObject(PyExc_ValueError,
329+
PyString_FromString(yajl_status_to_string(yrc)));
330330
return NULL;
331331
}
332332

333333
if (decoder->root == NULL) {
334-
fprintf(stderr, "FAIL : %s\n", yajl_status_to_string(yrc));
334+
PyErr_SetObject(PyExc_ValueError,
335+
PyString_FromString("The root object is NULL"));
335336
return NULL;
336337
}
337338

tests.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,10 @@ def setUp(self):
5050
self.d = yajl.Decoder()
5151

5252
def test_EmptyString(self):
53-
rc = self.d.decode('')
54-
print ('rc', rc)
53+
self.failUnlessRaises(ValueError, self.d.decode, '')
5554

5655
def test_None(self):
57-
rc = self.d.decode(None)
58-
print ('rc', rc)
56+
self.failUnlessRaises(ValueError, self.d.decode, None)
5957

6058

6159
if __name__ == '__main__':

0 commit comments

Comments
 (0)