diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2015-08-02 23:49:19 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2015-08-02 23:49:19 -0400 |
commit | 89e80b03297555277473fc3978b83c68ec9847b8 (patch) | |
tree | 3d83744f8f80cc85eb31864340760df7029f6e3b /contrib/tablefunc | |
parent | c75b1f75b3d159c0e71c1ec7f42c922bce448d89 (diff) | |
download | postgresql-89e80b03297555277473fc3978b83c68ec9847b8.tar.gz |
Fix a number of places that produced XX000 errors in the regression tests.
It's against project policy to use elog() for user-facing errors, or to
omit an errcode() selection for errors that aren't supposed to be "can't
happen" cases. Fix all the violations of this policy that result in
ERRCODE_INTERNAL_ERROR log entries during the standard regression tests,
as errors that can reliably be triggered from SQL surely should be
considered user-facing.
I also looked through all the files touched by this commit and fixed
other nearby problems of the same ilk. I do not claim to have fixed
all violations of the policy, just the ones in these files.
In a few places I also changed existing ERRCODE choices that didn't
seem particularly appropriate; mainly replacing ERRCODE_SYNTAX_ERROR
by something more specific.
Back-patch to 9.5, but no further; changing ERRCODE assignments in
stable branches doesn't seem like a good idea.
Diffstat (limited to 'contrib/tablefunc')
-rw-r--r-- | contrib/tablefunc/tablefunc.c | 40 |
1 files changed, 25 insertions, 15 deletions
diff --git a/contrib/tablefunc/tablefunc.c b/contrib/tablefunc/tablefunc.c index 8a95d4710b..cb1d029bf5 100644 --- a/contrib/tablefunc/tablefunc.c +++ b/contrib/tablefunc/tablefunc.c @@ -432,7 +432,9 @@ crosstab(PG_FUNCTION_ARGS) break; default: /* result type isn't composite */ - elog(ERROR, "return type must be a row type"); + ereport(ERROR, + (errcode(ERRCODE_DATATYPE_MISMATCH), + errmsg("return type must be a row type"))); break; } @@ -1350,7 +1352,9 @@ build_tuplestore_recursively(char *key_fld, appendStringInfo(&chk_current_key, "%s%s%s", branch_delim, current_key, branch_delim); if (strstr(chk_branchstr.data, chk_current_key.data)) - elog(ERROR, "infinite recursion detected"); + ereport(ERROR, + (errcode(ERRCODE_INVALID_RECURSION), + errmsg("infinite recursion detected"))); } /* OK, extend the branch */ @@ -1429,7 +1433,7 @@ validateConnectbyTupleDesc(TupleDesc tupdesc, bool show_branch, bool show_serial { if (tupdesc->natts != (CONNECTBY_NCOLS + serial_column)) ereport(ERROR, - (errcode(ERRCODE_SYNTAX_ERROR), + (errcode(ERRCODE_DATATYPE_MISMATCH), errmsg("invalid return type"), errdetail("Query-specified return tuple has " \ "wrong number of columns."))); @@ -1438,7 +1442,7 @@ validateConnectbyTupleDesc(TupleDesc tupdesc, bool show_branch, bool show_serial { if (tupdesc->natts != CONNECTBY_NCOLS_NOBRANCH + serial_column) ereport(ERROR, - (errcode(ERRCODE_SYNTAX_ERROR), + (errcode(ERRCODE_DATATYPE_MISMATCH), errmsg("invalid return type"), errdetail("Query-specified return tuple has " \ "wrong number of columns."))); @@ -1447,14 +1451,14 @@ validateConnectbyTupleDesc(TupleDesc tupdesc, bool show_branch, bool show_serial /* check that the types of the first two columns match */ if (tupdesc->attrs[0]->atttypid != tupdesc->attrs[1]->atttypid) ereport(ERROR, - (errcode(ERRCODE_SYNTAX_ERROR), + (errcode(ERRCODE_DATATYPE_MISMATCH), errmsg("invalid return type"), errdetail("First two columns must be the same type."))); /* check that the type of the third column is INT4 */ if (tupdesc->attrs[2]->atttypid != INT4OID) ereport(ERROR, - (errcode(ERRCODE_SYNTAX_ERROR), + (errcode(ERRCODE_DATATYPE_MISMATCH), errmsg("invalid return type"), errdetail("Third column must be type %s.", format_type_be(INT4OID)))); @@ -1462,20 +1466,26 @@ validateConnectbyTupleDesc(TupleDesc tupdesc, bool show_branch, bool show_serial /* check that the type of the fourth column is TEXT if applicable */ if (show_branch && tupdesc->attrs[3]->atttypid != TEXTOID) ereport(ERROR, - (errcode(ERRCODE_SYNTAX_ERROR), + (errcode(ERRCODE_DATATYPE_MISMATCH), errmsg("invalid return type"), errdetail("Fourth column must be type %s.", format_type_be(TEXTOID)))); /* check that the type of the fifth column is INT4 */ if (show_branch && show_serial && tupdesc->attrs[4]->atttypid != INT4OID) - elog(ERROR, "query-specified return tuple not valid for Connectby: " - "fifth column must be type %s", format_type_be(INT4OID)); + ereport(ERROR, + (errcode(ERRCODE_DATATYPE_MISMATCH), + errmsg("query-specified return tuple not valid for Connectby: " + "fifth column must be type %s", + format_type_be(INT4OID)))); /* check that the type of the fifth column is INT4 */ if (!show_branch && show_serial && tupdesc->attrs[3]->atttypid != INT4OID) - elog(ERROR, "query-specified return tuple not valid for Connectby: " - "fourth column must be type %s", format_type_be(INT4OID)); + ereport(ERROR, + (errcode(ERRCODE_DATATYPE_MISMATCH), + errmsg("query-specified return tuple not valid for Connectby: " + "fourth column must be type %s", + format_type_be(INT4OID)))); /* OK, the tupdesc is valid for our purposes */ } @@ -1496,7 +1506,7 @@ compatConnectbyTupleDescs(TupleDesc ret_tupdesc, TupleDesc sql_tupdesc) */ if (sql_tupdesc->natts < 2) ereport(ERROR, - (errcode(ERRCODE_SYNTAX_ERROR), + (errcode(ERRCODE_DATATYPE_MISMATCH), errmsg("invalid return type"), errdetail("Query must return at least two columns."))); @@ -1511,7 +1521,7 @@ compatConnectbyTupleDescs(TupleDesc ret_tupdesc, TupleDesc sql_tupdesc) if (ret_atttypid != sql_atttypid || (ret_atttypmod >= 0 && ret_atttypmod != sql_atttypmod)) ereport(ERROR, - (errcode(ERRCODE_SYNTAX_ERROR), + (errcode(ERRCODE_DATATYPE_MISMATCH), errmsg("invalid return type"), errdetail("SQL key field type %s does " \ "not match return key field type %s.", @@ -1525,7 +1535,7 @@ compatConnectbyTupleDescs(TupleDesc ret_tupdesc, TupleDesc sql_tupdesc) if (ret_atttypid != sql_atttypid || (ret_atttypmod >= 0 && ret_atttypmod != sql_atttypmod)) ereport(ERROR, - (errcode(ERRCODE_SYNTAX_ERROR), + (errcode(ERRCODE_DATATYPE_MISMATCH), errmsg("invalid return type"), errdetail("SQL parent key field type %s does " \ "not match return parent key field type %s.", @@ -1556,7 +1566,7 @@ compatCrosstabTupleDescs(TupleDesc ret_tupdesc, TupleDesc sql_tupdesc) sql_atttypid = sql_tupdesc->attrs[0]->atttypid; if (ret_atttypid != sql_atttypid) ereport(ERROR, - (errcode(ERRCODE_SYNTAX_ERROR), + (errcode(ERRCODE_DATATYPE_MISMATCH), errmsg("invalid return type"), errdetail("SQL rowid datatype does not match " \ "return rowid datatype."))); |