From 582b5ac62e74a553e72151b321804a7b2e5fed6f Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Thu, 27 Jan 2011 00:47:14 +0200 Subject: Improve exception usage in PL/Python MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use the built-in TypeError, not SPIError, for errors having to do with argument counts or types. Use SPIError, not simply plpy.Error, for errors in PLy_spi_execute_plan. Finally, do not set a Python exception if PyArg_ParseTuple failed, as it already sets the correct exception. Jan UrbaƄski --- src/pl/plpython/plpython.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'src/pl/plpython/plpython.c') diff --git a/src/pl/plpython/plpython.c b/src/pl/plpython/plpython.c index 6bcb4cc049b..21cb106b80c 100644 --- a/src/pl/plpython/plpython.c +++ b/src/pl/plpython/plpython.c @@ -2820,15 +2820,11 @@ PLy_spi_prepare(PyObject *self, PyObject *args) int nargs; if (!PyArg_ParseTuple(args, "s|O", &query, &list)) - { - PLy_exception_set(PLy_exc_spi_error, - "invalid arguments for plpy.prepare"); return NULL; - } if (list && (!PySequence_Check(list))) { - PLy_exception_set(PLy_exc_spi_error, + PLy_exception_set(PyExc_TypeError, "second argument of plpy.prepare must be a sequence"); return NULL; } @@ -2984,7 +2980,7 @@ PLy_spi_execute_plan(PyObject *ob, PyObject *list, long limit) { if (!PySequence_Check(list) || PyString_Check(list) || PyUnicode_Check(list)) { - PLy_exception_set(PLy_exc_spi_error, "plpy.execute takes a sequence as its second argument"); + PLy_exception_set(PyExc_TypeError, "plpy.execute takes a sequence as its second argument"); return NULL; } nargs = PySequence_Length(list); @@ -3002,7 +2998,7 @@ PLy_spi_execute_plan(PyObject *ob, PyObject *list, long limit) if (!so) PLy_elog(ERROR, "could not execute plan"); sv = PyString_AsString(so); - PLy_exception_set_plural(PLy_exc_spi_error, + PLy_exception_set_plural(PyExc_TypeError, "Expected sequence of %d argument, got %d: %s", "Expected sequence of %d arguments, got %d: %s", plan->nargs, @@ -3089,7 +3085,7 @@ PLy_spi_execute_plan(PyObject *ob, PyObject *list, long limit) } if (!PyErr_Occurred()) - PLy_exception_set(PLy_exc_error, + PLy_exception_set(PLy_exc_spi_error, "unrecognized error in PLy_spi_execute_plan"); PLy_elog(WARNING, NULL); PLy_spi_exception_set(edata); -- cgit v1.2.3