Skip to content

Commit 26b8361

Browse files
committed
Tidy up error reporting when converting PL/Python arrays.
Use PLy_elog() only when a call to a Python C API function failed, and ereport() for other errors. Add an error code to the "wrong length of inner sequence" ereport(). Reviewed-by: Daniel Gustafsson Discussion: https://www.postgresql.org/message-id/B8B72889-D6D7-48FF-B782-D670A6CA4D37%40yesql.se
1 parent 8550cbd commit 26b8361

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/pl/plpython/plpy_typeio.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,18 +1173,25 @@ PLySequence_ToArray(PLyObToDatum *arg, PyObject *plrv,
11731173
break;
11741174

11751175
if (ndim == MAXDIM)
1176-
PLy_elog(ERROR, "number of array dimensions exceeds the maximum allowed (%d)", MAXDIM);
1176+
ereport(ERROR,
1177+
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
1178+
errmsg("number of array dimensions exceeds the maximum allowed (%d)",
1179+
MAXDIM)));
11771180

11781181
dims[ndim] = PySequence_Length(pyptr);
11791182
if (dims[ndim] < 0)
11801183
PLy_elog(ERROR, "could not determine sequence length for function return value");
11811184

11821185
if (dims[ndim] > MaxAllocSize)
1183-
PLy_elog(ERROR, "array size exceeds the maximum allowed");
1186+
ereport(ERROR,
1187+
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
1188+
errmsg("array size exceeds the maximum allowed")));
11841189

11851190
len *= dims[ndim];
11861191
if (len > MaxAllocSize)
1187-
PLy_elog(ERROR, "array size exceeds the maximum allowed");
1192+
ereport(ERROR,
1193+
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
1194+
errmsg("array size exceeds the maximum allowed")));
11881195

11891196
if (dims[ndim] == 0)
11901197
{
@@ -1210,7 +1217,9 @@ PLySequence_ToArray(PLyObToDatum *arg, PyObject *plrv,
12101217
if (ndim == 0)
12111218
{
12121219
if (!PySequence_Check(plrv))
1213-
PLy_elog(ERROR, "return value of function with array return type is not a Python sequence");
1220+
ereport(ERROR,
1221+
(errcode(ERRCODE_DATATYPE_MISMATCH),
1222+
errmsg("return value of function with array return type is not a Python sequence")));
12141223

12151224
ndim = 1;
12161225
len = dims[0] = PySequence_Length(plrv);
@@ -1256,7 +1265,8 @@ PLySequence_ToArray_recurse(PLyObToDatum *elm, PyObject *list,
12561265

12571266
if (PySequence_Length(list) != dims[dim])
12581267
ereport(ERROR,
1259-
(errmsg("wrong length of inner sequence: has length %d, but %d was expected",
1268+
(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
1269+
errmsg("wrong length of inner sequence: has length %d, but %d was expected",
12601270
(int) PySequence_Length(list), dims[dim]),
12611271
(errdetail("To construct a multidimensional array, the inner sequences must all have the same length."))));
12621272

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy