diff --git a/src/pl/plperl/eloglvl.c b/src/pl/plperl/eloglvl.c index bfa2e56e41..3baf027901 100644 --- a/src/pl/plperl/eloglvl.c +++ b/src/pl/plperl/eloglvl.c @@ -1,7 +1,5 @@ #include "postgres.h" -#include "utils/elog.h" - /* * This kludge is necessary because of the conflicting * definitions of 'DEBUG' between postgres and perl. diff --git a/src/pl/plperl/plperl.c b/src/pl/plperl/plperl.c index e4ad4102ac..fcbe55c9c2 100644 --- a/src/pl/plperl/plperl.c +++ b/src/pl/plperl/plperl.c @@ -33,7 +33,7 @@ * ENHANCEMENTS, OR MODIFICATIONS. * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/pl/plperl/plperl.c,v 1.36 2003/04/20 21:15:34 tgl Exp $ + * $Header: /cvsroot/pgsql/src/pl/plperl/plperl.c,v 1.37 2003/07/25 23:37:28 tgl Exp $ * **********************************************************************/ @@ -47,7 +47,6 @@ /* postgreSQL stuff */ #include "executor/spi.h" #include "commands/trigger.h" -#include "utils/elog.h" #include "fmgr.h" #include "access/heapam.h" #include "tcop/tcopprot.h" @@ -193,7 +192,7 @@ plperl_init_interp(void) plperl_interp = perl_alloc(); if (!plperl_interp) - elog(ERROR, "plperl_init_interp(): could not allocate perl interpreter"); + elog(ERROR, "could not allocate perl interpreter"); perl_construct(plperl_interp); perl_parse(plperl_interp, plperl_init_shared_libs, 3, embedding, NULL); @@ -232,7 +231,7 @@ plperl_call_handler(PG_FUNCTION_ARGS) * Connect to SPI manager ************************************************************/ if (SPI_connect() != SPI_OK_CONNECT) - elog(ERROR, "plperl: cannot connect to SPI manager"); + elog(ERROR, "could not connect to SPI manager"); /************************************************************ * Determine if called as function or trigger and @@ -240,7 +239,9 @@ plperl_call_handler(PG_FUNCTION_ARGS) ************************************************************/ if (CALLED_AS_TRIGGER(fcinfo)) { - elog(ERROR, "plperl: can't use perl in triggers yet."); + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("cannot use perl in triggers yet"))); /* * retval = PointerGetDatum(plperl_trigger_handler(fcinfo)); @@ -286,7 +287,7 @@ plperl_create_sub(char *s, bool trusted) PUTBACK; FREETMPS; LEAVE; - elog(ERROR, "plperl: didn't get a return item from mksafefunc"); + elog(ERROR, "didn't get a return item from mksafefunc"); } if (SvTRUE(ERRSV)) @@ -314,7 +315,7 @@ plperl_create_sub(char *s, bool trusted) * subref is our responsibility because it is not mortal */ SvREFCNT_dec(subref); - elog(ERROR, "plperl_create_sub: didn't get a code ref"); + elog(ERROR, "didn't get a code ref"); } PUTBACK; @@ -406,7 +407,7 @@ plperl_call_perl_func(plperl_proc_desc * desc, FunctionCallInfo fcinfo) PUTBACK; FREETMPS; LEAVE; - elog(ERROR, "plperl: didn't get a return item from function"); + elog(ERROR, "didn't get a return item from function"); } if (SvTRUE(ERRSV)) @@ -415,7 +416,7 @@ plperl_call_perl_func(plperl_proc_desc * desc, FunctionCallInfo fcinfo) PUTBACK; FREETMPS; LEAVE; - elog(ERROR, "plperl: error from function: %s", SvPV(ERRSV, PL_na)); + elog(ERROR, "error from function: %s", SvPV(ERRSV, PL_na)); } retval = newSVsv(POPs); @@ -453,7 +454,7 @@ plperl_func_handler(PG_FUNCTION_ARGS) * because SPI_finish would free it). ************************************************************/ if (SPI_finish() != SPI_OK_FINISH) - elog(ERROR, "plperl: SPI_finish() failed"); + elog(ERROR, "SPI_finish() failed"); if (!(perlret && SvOK(perlret))) { @@ -493,7 +494,7 @@ compile_plperl_function(Oid fn_oid, bool is_trigger) ObjectIdGetDatum(fn_oid), 0, 0, 0); if (!HeapTupleIsValid(procTup)) - elog(ERROR, "plperl: cache lookup for proc %u failed", fn_oid); + elog(ERROR, "cache lookup failed for function %u", fn_oid); procStruct = (Form_pg_proc) GETSTRUCT(procTup); /************************************************************ @@ -551,7 +552,9 @@ compile_plperl_function(Oid fn_oid, bool is_trigger) ************************************************************/ prodesc = (plperl_proc_desc *) malloc(sizeof(plperl_proc_desc)); if (prodesc == NULL) - elog(ERROR, "plperl: out of memory"); + ereport(ERROR, + (errcode(ERRCODE_OUT_OF_MEMORY), + errmsg("out of memory"))); MemSet(prodesc, 0, sizeof(plperl_proc_desc)); prodesc->proname = strdup(internal_proname); prodesc->fn_xmin = HeapTupleHeaderGetXmin(procTup->t_data); @@ -567,7 +570,7 @@ compile_plperl_function(Oid fn_oid, bool is_trigger) { free(prodesc->proname); free(prodesc); - elog(ERROR, "plperl: cache lookup for language %u failed", + elog(ERROR, "cache lookup failed for language %u", procStruct->prolang); } langStruct = (Form_pg_language) GETSTRUCT(langTup); @@ -587,7 +590,7 @@ compile_plperl_function(Oid fn_oid, bool is_trigger) { free(prodesc->proname); free(prodesc); - elog(ERROR, "plperl: cache lookup for return type %u failed", + elog(ERROR, "cache lookup failed for type %u", procStruct->prorettype); } typeStruct = (Form_pg_type) GETSTRUCT(typeTup); @@ -601,16 +604,18 @@ compile_plperl_function(Oid fn_oid, bool is_trigger) { free(prodesc->proname); free(prodesc); - elog(ERROR, "plperl functions cannot return type %s" - "\n\texcept when used as triggers", - format_type_be(procStruct->prorettype)); + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("trigger functions may only be called as triggers"))); } else { free(prodesc->proname); free(prodesc); - elog(ERROR, "plperl functions cannot return type %s", - format_type_be(procStruct->prorettype)); + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("plperl functions cannot return type %s", + format_type_be(procStruct->prorettype)))); } } @@ -618,7 +623,9 @@ compile_plperl_function(Oid fn_oid, bool is_trigger) { free(prodesc->proname); free(prodesc); - elog(ERROR, "plperl: return types of tuples not supported yet"); + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("plperl functions cannot return tuples yet"))); } perm_fmgr_info(typeStruct->typinput, &(prodesc->result_in_func)); @@ -643,7 +650,7 @@ compile_plperl_function(Oid fn_oid, bool is_trigger) { free(prodesc->proname); free(prodesc); - elog(ERROR, "plperl: cache lookup for argument type %u failed", + elog(ERROR, "cache lookup failed for type %u", procStruct->proargtypes[i]); } typeStruct = (Form_pg_type) GETSTRUCT(typeTup); @@ -653,8 +660,10 @@ compile_plperl_function(Oid fn_oid, bool is_trigger) { free(prodesc->proname); free(prodesc); - elog(ERROR, "plperl functions cannot take type %s", - format_type_be(procStruct->proargtypes[i])); + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("plperl functions cannot take type %s", + format_type_be(procStruct->proargtypes[i])))); } if (typeStruct->typrelid != InvalidOid) @@ -686,7 +695,7 @@ compile_plperl_function(Oid fn_oid, bool is_trigger) { free(prodesc->proname); free(prodesc); - elog(ERROR, "plperl: cannot create internal procedure %s", + elog(ERROR, "could not create internal procedure \"%s\"", internal_proname); } @@ -751,8 +760,8 @@ plperl_build_tuple_argument(HeapTuple tuple, TupleDesc tupdesc) ObjectIdGetDatum(tupdesc->attrs[i]->atttypid), 0, 0, 0); if (!HeapTupleIsValid(typeTup)) - elog(ERROR, "plperl: Cache lookup for attribute '%s' type %u failed", - attname, tupdesc->attrs[i]->atttypid); + elog(ERROR, "cache lookup failed for type %u", + tupdesc->attrs[i]->atttypid); typoutput = ((Form_pg_type) GETSTRUCT(typeTup))->typoutput; typelem = ((Form_pg_type) GETSTRUCT(typeTup))->typelem; diff --git a/src/pl/plpgsql/src/gram.y b/src/pl/plpgsql/src/gram.y index 107946c336..8f0f76a4ea 100644 --- a/src/pl/plpgsql/src/gram.y +++ b/src/pl/plpgsql/src/gram.y @@ -4,7 +4,7 @@ * procedural language * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/pl/plpgsql/src/gram.y,v 1.44 2003/05/27 17:49:47 momjian Exp $ + * $Header: /cvsroot/pgsql/src/pl/plpgsql/src/gram.y,v 1.45 2003/07/25 23:37:28 tgl Exp $ * * This software is copyrighted by Jan Wieck - Hamburg. * @@ -340,11 +340,17 @@ decl_statement : decl_varname decl_const decl_datatype decl_notnull decl_defval row->lineno = $1.lineno; if ($2) - elog(ERROR, "Rowtype variable cannot be CONSTANT"); + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("rowtype variable cannot be CONSTANT"))); if ($4) - elog(ERROR, "Rowtype variable cannot be NOT NULL"); + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("rowtype variable cannot be NOT NULL"))); if ($5 != NULL) - elog(ERROR, "Default value for rowtype variable is not supported"); + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("default value for rowtype variable is not supported"))); plpgsql_adddatum((PLpgSQL_datum *)row); plpgsql_ns_additem(PLPGSQL_NSTYPE_ROW, @@ -554,7 +560,10 @@ decl_aliasitem : T_WORD if (nsi == NULL) { plpgsql_error_lineno = plpgsql_scanner_lineno(); - elog(ERROR, "function has no parameter %s", name); + ereport(ERROR, + (errcode(ERRCODE_UNDEFINED_PARAMETER), + errmsg("function has no parameter \"%s\"", + name))); } plpgsql_ns_setlocal(true); @@ -1087,7 +1096,8 @@ stmt_fors : opt_label K_FOR lno fors_target K_IN K_SELECT expr_until_loop loop_ new->row = (PLpgSQL_row *)$4; break; default: - elog(ERROR, "unknown dtype %d in stmt_fors", $4->dtype); + elog(ERROR, "unrecognized dtype: %d", + $4->dtype); } new->query = $7; new->body = $8; @@ -1117,7 +1127,8 @@ stmt_dynfors : opt_label K_FOR lno fors_target K_IN K_EXECUTE expr_until_loop lo new->row = (PLpgSQL_row *)$4; break; default: - elog(ERROR, "unknown dtype %d in stmt_dynfors", $4->dtype); + elog(ERROR, "unrecognized dtype: %d", + $4->dtype); } new->query = $7; new->body = $8; @@ -1375,7 +1386,11 @@ stmt_open : K_OPEN lno cursor_varptr if (tok != K_FOR) { plpgsql_error_lineno = $2; - elog(ERROR, "syntax error at \"%s\" - expected FOR to open a reference cursor", yytext); + ereport(ERROR, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("syntax error at \"%s\"", + yytext), + errdetail("Expected FOR to open a reference cursor."))); } tok = yylex(); @@ -1391,7 +1406,10 @@ stmt_open : K_OPEN lno cursor_varptr default: plpgsql_error_lineno = $2; - elog(ERROR, "syntax error at \"%s\"", yytext); + ereport(ERROR, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("syntax error at \"%s\"", + yytext))); } } @@ -1406,8 +1424,10 @@ stmt_open : K_OPEN lno cursor_varptr if (tok != '(') { plpgsql_error_lineno = plpgsql_scanner_lineno(); - elog(ERROR, "cursor %s has arguments", - $3->refname); + ereport(ERROR, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("cursor \"%s\" has arguments", + $3->refname))); } /* @@ -1428,7 +1448,8 @@ stmt_open : K_OPEN lno cursor_varptr if (strncmp(cp, "SELECT", 6) != 0) { plpgsql_error_lineno = plpgsql_scanner_lineno(); - elog(ERROR, "expected 'SELECT (', got '%s' (internal error)", + /* internal error */ + elog(ERROR, "expected \"SELECT (\", got \"%s\"", new->argquery->query); } cp += 6; @@ -1437,7 +1458,8 @@ stmt_open : K_OPEN lno cursor_varptr if (*cp != '(') { plpgsql_error_lineno = plpgsql_scanner_lineno(); - elog(ERROR, "expected 'SELECT (', got '%s' (internal error)", + /* internal error */ + elog(ERROR, "expected \"SELECT (\", got \"%s\"", new->argquery->query); } *cp = ' '; @@ -1455,13 +1477,19 @@ stmt_open : K_OPEN lno cursor_varptr if (tok == '(') { plpgsql_error_lineno = plpgsql_scanner_lineno(); - elog(ERROR, "cursor %s has no arguments", $3->refname); + ereport(ERROR, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("cursor \"%s\" has no arguments", + $3->refname))); } if (tok != ';') { plpgsql_error_lineno = plpgsql_scanner_lineno(); - elog(ERROR, "syntax error at \"%s\"", yytext); + ereport(ERROR, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("syntax error at \"%s\"", + yytext))); } } } @@ -1503,8 +1531,10 @@ cursor_varptr : T_VARIABLE if (((PLpgSQL_var *) yylval.variable)->datatype->typoid != REFCURSOROID) { plpgsql_error_lineno = plpgsql_scanner_lineno(); - elog(ERROR, "%s must be of type cursor or refcursor", - ((PLpgSQL_var *) yylval.variable)->refname); + ereport(ERROR, + (errcode(ERRCODE_DATATYPE_MISMATCH), + errmsg("\"%s\" must be of type cursor or refcursor", + ((PLpgSQL_var *) yylval.variable)->refname))); } $$ = (PLpgSQL_var *) yylval.variable; } @@ -1518,8 +1548,10 @@ cursor_variable : T_VARIABLE if (((PLpgSQL_var *) yylval.variable)->datatype->typoid != REFCURSOROID) { plpgsql_error_lineno = plpgsql_scanner_lineno(); - elog(ERROR, "%s must be of type refcursor", - ((PLpgSQL_var *) yylval.variable)->refname); + ereport(ERROR, + (errcode(ERRCODE_DATATYPE_MISMATCH), + errmsg("\"%s\" must be of type refcursor", + ((PLpgSQL_var *) yylval.variable)->refname))); } $$ = yylval.variable->dno; } @@ -1632,7 +1664,9 @@ read_sql_construct(int until, { parenlevel--; if (parenlevel < 0) - elog(ERROR, "mismatched parentheses"); + ereport(ERROR, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("mismatched parentheses"))); } /* * End of function definition is an error, and we don't expect to @@ -1643,13 +1677,19 @@ read_sql_construct(int until, { plpgsql_error_lineno = lno; if (parenlevel != 0) - elog(ERROR, "mismatched parentheses"); + ereport(ERROR, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("mismatched parentheses"))); if (isexpression) - elog(ERROR, "missing %s at end of SQL expression", - expected); + ereport(ERROR, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("missing \"%s\" at end of SQL expression", + expected))); else - elog(ERROR, "missing %s at end of SQL statement", - expected); + ereport(ERROR, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("missing \"%s\" at end of SQL statement", + expected))); break; } if (plpgsql_SpaceScanned) @@ -1709,8 +1749,12 @@ read_datatype(int tok) { plpgsql_error_lineno = lno; if (parenlevel != 0) - elog(ERROR, "mismatched parentheses"); - elog(ERROR, "incomplete datatype declaration"); + ereport(ERROR, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("mismatched parentheses"))); + ereport(ERROR, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("incomplete datatype declaration"))); } /* Possible followers for datatype in a declaration */ if (tok == K_NOT || tok == K_ASSIGN || tok == K_DEFAULT) @@ -1769,14 +1813,18 @@ make_select_stmt(void) if (tok == 0) { plpgsql_error_lineno = plpgsql_scanner_lineno(); - elog(ERROR, "unexpected end of file"); + ereport(ERROR, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("unexpected end of function definition"))); } if (tok == K_INTO) { if (have_into) { plpgsql_error_lineno = plpgsql_scanner_lineno(); - elog(ERROR, "INTO specified more than once"); + ereport(ERROR, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("INTO specified more than once"))); } tok = yylex(); switch (tok) @@ -1814,8 +1862,10 @@ make_select_stmt(void) default: plpgsql_error_lineno = plpgsql_scanner_lineno(); - elog(ERROR, "plpgsql: %s is not a variable", - yytext); + ereport(ERROR, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("\"%s\" is not a variable", + yytext))); } } have_nexttok = 1; @@ -1945,8 +1995,10 @@ make_fetch_stmt(void) default: plpgsql_error_lineno = plpgsql_scanner_lineno(); - elog(ERROR, "plpgsql: %s is not a variable", - yytext); + ereport(ERROR, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("\"%s\" is not a variable", + yytext))); } } have_nexttok = 1; @@ -2028,8 +2080,10 @@ check_assignable(PLpgSQL_datum *datum) if (((PLpgSQL_var *) datum)->isconst) { plpgsql_error_lineno = plpgsql_scanner_lineno(); - elog(ERROR, "%s is declared CONSTANT", - ((PLpgSQL_var *) datum)->refname); + ereport(ERROR, + (errcode(ERRCODE_ERROR_IN_ASSIGNMENT), + errmsg("\"%s\" is declared CONSTANT", + ((PLpgSQL_var *) datum)->refname))); } break; case PLPGSQL_DTYPE_RECFIELD: diff --git a/src/pl/plpgsql/src/pl_comp.c b/src/pl/plpgsql/src/pl_comp.c index b9867dd6db..1a84cdfd66 100644 --- a/src/pl/plpgsql/src/pl_comp.c +++ b/src/pl/plpgsql/src/pl_comp.c @@ -3,7 +3,7 @@ * procedural language * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_comp.c,v 1.59 2003/07/01 21:47:09 tgl Exp $ + * $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_comp.c,v 1.60 2003/07/25 23:37:28 tgl Exp $ * * This software is copyrighted by Jan Wieck - Hamburg. * @@ -154,7 +154,7 @@ plpgsql_compile(FunctionCallInfo fcinfo) ObjectIdGetDatum(funcOid), 0, 0, 0); if (!HeapTupleIsValid(procTup)) - elog(ERROR, "plpgsql: cache lookup for proc %u failed", funcOid); + elog(ERROR, "cache lookup failed for function %u", funcOid); procStruct = (Form_pg_proc) GETSTRUCT(procTup); /* @@ -301,15 +301,21 @@ do_compile(FunctionCallInfo fcinfo, * Check for a polymorphic returntype. If found, use the actual * returntype type from the caller's FuncExpr node, if we * have one. + * + * Note: errcode is FEATURE_NOT_SUPPORTED because it should always + * work; if it doesn't we're in some context that fails to make + * the info available. */ rettypeid = procStruct->prorettype; if (rettypeid == ANYARRAYOID || rettypeid == ANYELEMENTOID) { rettypeid = get_fn_expr_rettype(fcinfo->flinfo); if (!OidIsValid(rettypeid)) - elog(ERROR, "could not determine actual return type " - "for polymorphic function %s", - plpgsql_error_funcname); + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("could not determine actual return type " + "for polymorphic function \"%s\"", + plpgsql_error_funcname))); } /* @@ -325,8 +331,7 @@ do_compile(FunctionCallInfo fcinfo, ObjectIdGetDatum(rettypeid), 0, 0, 0); if (!HeapTupleIsValid(typeTup)) - elog(ERROR, "cache lookup for return type %u failed", - rettypeid); + elog(ERROR, "cache lookup failed for type %u", rettypeid); typeStruct = (Form_pg_type) GETSTRUCT(typeTup); /* Disallow pseudotype result, except VOID or RECORD */ @@ -337,12 +342,14 @@ do_compile(FunctionCallInfo fcinfo, rettypeid == RECORDOID) /* okay */ ; else if (rettypeid == TRIGGEROID) - elog(ERROR, "plpgsql functions cannot return type %s" - "\n\texcept when used as triggers", - format_type_be(rettypeid)); + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("trigger functions may only be called as triggers"))); else - elog(ERROR, "plpgsql functions cannot return type %s", - format_type_be(rettypeid)); + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("plpgsql functions cannot return type %s", + format_type_be(rettypeid)))); } if (typeStruct->typrelid != InvalidOid || @@ -382,15 +389,16 @@ do_compile(FunctionCallInfo fcinfo, ObjectIdGetDatum(argtypeid), 0, 0, 0); if (!HeapTupleIsValid(typeTup)) - elog(ERROR, "cache lookup for argument type %u failed", - argtypeid); + elog(ERROR, "cache lookup failed for type %u", argtypeid); typeStruct = (Form_pg_type) GETSTRUCT(typeTup); /* Disallow pseudotype argument */ /* (note we already replaced ANYARRAY/ANYELEMENT) */ if (typeStruct->typtype == 'p') - elog(ERROR, "plpgsql functions cannot take type %s", - format_type_be(argtypeid)); + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("plpgsql functions cannot take type %s", + format_type_be(argtypeid)))); if (typeStruct->typrelid != InvalidOid) { @@ -601,8 +609,7 @@ do_compile(FunctionCallInfo fcinfo, break; default: - elog(ERROR, "unknown function type %u in plpgsql_compile()", - functype); + elog(ERROR, "unrecognized function typecode: %u", functype); break; } @@ -634,7 +641,7 @@ do_compile(FunctionCallInfo fcinfo, */ parse_rc = plpgsql_yyparse(); if (parse_rc != 0) - elog(ERROR, "plpgsql: parser returned %d ???", parse_rc); + elog(ERROR, "plpgsql parser returned %d", parse_rc); plpgsql_scanner_finish(); @@ -864,8 +871,10 @@ plpgsql_parse_dblword(char *word) return T_VARIABLE; } } - elog(ERROR, "row %s doesn't have a field %s", - cp[0], cp[1]); + ereport(ERROR, + (errcode(ERRCODE_UNDEFINED_COLUMN), + errmsg("row \"%s\" has no field \"%s\"", + cp[0], cp[1]))); } default: @@ -969,8 +978,10 @@ plpgsql_parse_tripword(char *word) return T_VARIABLE; } } - elog(ERROR, "row %s.%s doesn't have a field %s", - cp[0], cp[1], cp[2]); + ereport(ERROR, + (errcode(ERRCODE_UNDEFINED_COLUMN), + errmsg("row \"%s.%s\" has no field \"%s\"", + cp[0], cp[1], cp[2]))); } default: @@ -1188,8 +1199,7 @@ plpgsql_parse_dblwordtype(char *word) ObjectIdGetDatum(attrStruct->atttypid), 0, 0, 0); if (!HeapTupleIsValid(typetup)) - elog(ERROR, "cache lookup for type %u of %s.%s failed", - attrStruct->atttypid, cp[0], cp[1]); + elog(ERROR, "cache lookup failed for type %u", attrStruct->atttypid); /* * Found that - build a compiler type struct and return it @@ -1300,8 +1310,7 @@ plpgsql_parse_tripwordtype(char *word) ObjectIdGetDatum(attrStruct->atttypid), 0, 0, 0); if (!HeapTupleIsValid(typetup)) - elog(ERROR, "cache lookup for type %u of %s.%s failed", - attrStruct->atttypid, cp[0], cp[1]); + elog(ERROR, "cache lookup failed for type %u", attrStruct->atttypid); /* * Found that - build a compiler type struct and return it @@ -1339,7 +1348,9 @@ plpgsql_parse_wordrowtype(char *word) /* Lookup the relation */ classOid = RelnameGetRelid(cp[0]); if (!OidIsValid(classOid)) - elog(ERROR, "%s: no such class", cp[0]); + ereport(ERROR, + (errcode(ERRCODE_UNDEFINED_TABLE), + errmsg("relation \"%s\" does not exist", cp[0]))); /* * Build and return the complete row definition @@ -1380,7 +1391,9 @@ plpgsql_parse_dblwordrowtype(char *word) relvar = makeRangeVarFromNameList(stringToQualifiedNameList(cp, "plpgsql_parse_dblwordrowtype")); classOid = RangeVarGetRelid(relvar, true); if (!OidIsValid(classOid)) - elog(ERROR, "%s: no such class", cp); + ereport(ERROR, + (errcode(ERRCODE_UNDEFINED_TABLE), + errmsg("relation \"%s\" does not exist", cp))); /* * Build and return the complete row definition @@ -1420,7 +1433,9 @@ plpgsql_build_rowtype(Oid classOid) classStruct->relkind != RELKIND_SEQUENCE && classStruct->relkind != RELKIND_VIEW && classStruct->relkind != RELKIND_COMPOSITE_TYPE) - elog(ERROR, "%s isn't a table", relname); + ereport(ERROR, + (errcode(ERRCODE_WRONG_OBJECT_TYPE), + errmsg("relation \"%s\" is not a table", relname))); /* * Create a row datum entry and all the required variables that it @@ -1451,8 +1466,8 @@ plpgsql_build_rowtype(Oid classOid) Int16GetDatum(i + 1), 0, 0); if (!HeapTupleIsValid(attrtup)) - elog(ERROR, "cache lookup for attribute %d of class %s failed", - i + 1, relname); + elog(ERROR, "cache lookup failed for attribute %d of relation %u", + i + 1, classOid); attrStruct = (Form_pg_attribute) GETSTRUCT(attrtup); attname = NameStr(attrStruct->attname); @@ -1461,8 +1476,8 @@ plpgsql_build_rowtype(Oid classOid) ObjectIdGetDatum(attrStruct->atttypid), 0, 0, 0); if (!HeapTupleIsValid(typetup)) - elog(ERROR, "cache lookup for type %u of %s.%s failed", - attrStruct->atttypid, relname, attname); + elog(ERROR, "cache lookup failed for type %u", + attrStruct->atttypid); /* * Create the internal variable @@ -1639,7 +1654,10 @@ void plpgsql_yyerror(const char *s) { plpgsql_error_lineno = plpgsql_scanner_lineno(); - elog(ERROR, "%s at or near \"%s\"", s, plpgsql_yytext); + ereport(ERROR, + (errcode(ERRCODE_SYNTAX_ERROR), + /* translator: first %s is a phrase like "syntax error" */ + errmsg("%s at or near \"%s\"", s, plpgsql_yytext))); } @@ -1678,9 +1696,11 @@ compute_function_hashkey(FmgrInfo *flinfo, { argtypeid = get_fn_expr_argtype(flinfo, i); if (!OidIsValid(argtypeid)) - elog(ERROR, "could not determine actual argument " - "type for polymorphic function %s", - NameStr(procStruct->proname)); + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("could not determine actual argument " + "type for polymorphic function \"%s\"", + NameStr(procStruct->proname)))); } hashkey->argtypes[i] = argtypeid; @@ -1729,9 +1749,11 @@ plpgsql_HashTableInsert(PLpgSQL_function *function, HASH_ENTER, &found); if (hentry == NULL) - elog(ERROR, "out of memory in plpgsql_HashTable"); + ereport(ERROR, + (errcode(ERRCODE_OUT_OF_MEMORY), + errmsg("out of memory"))); if (found) - elog(WARNING, "trying to insert a function that exists"); + elog(WARNING, "trying to insert a function that already exists"); hentry->function = function; /* prepare back link from function to hashtable key */ diff --git a/src/pl/plpgsql/src/pl_exec.c b/src/pl/plpgsql/src/pl_exec.c index 54f2b3a880..dfa508a94a 100644 --- a/src/pl/plpgsql/src/pl_exec.c +++ b/src/pl/plpgsql/src/pl_exec.c @@ -3,7 +3,7 @@ * procedural language * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.87 2003/06/29 00:33:44 tgl Exp $ + * $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.88 2003/07/25 23:37:28 tgl Exp $ * * This software is copyrighted by Jan Wieck - Hamburg. * @@ -212,8 +212,7 @@ plpgsql_exec_function(PLpgSQL_function * func, FunctionCallInfo fcinfo) break; default: - elog(ERROR, "unknown dtype %d in plpgsql_exec_function()", - func->datums[i]->dtype); + elog(ERROR, "unrecognized dtype: %d", func->datums[i]->dtype); } } @@ -252,8 +251,7 @@ plpgsql_exec_function(PLpgSQL_function * func, FunctionCallInfo fcinfo) break; default: - elog(ERROR, "unknown dtype %d in plpgsql_exec_function()", - func->datums[i]->dtype); + elog(ERROR, "unrecognized dtype: %d", func->datums[i]->dtype); } } @@ -283,8 +281,7 @@ plpgsql_exec_function(PLpgSQL_function * func, FunctionCallInfo fcinfo) break; default: - elog(ERROR, "unknown dtype %d in plpgsql_exec_function()", - func->datums[i]->dtype); + elog(ERROR, "unrecognized dtype: %d", func->datums[i]->dtype); } } @@ -302,7 +299,9 @@ plpgsql_exec_function(PLpgSQL_function * func, FunctionCallInfo fcinfo) { estate.err_stmt = NULL; estate.err_text = "at END of toplevel PL block"; - elog(ERROR, "control reaches end of function without RETURN"); + ereport(ERROR, + (errcode(ERRCODE_S_R_E_FUNCTION_EXECUTED_NO_RETURN_STATEMENT), + errmsg("control reached end of function without RETURN"))); } /* @@ -320,7 +319,9 @@ plpgsql_exec_function(PLpgSQL_function * func, FunctionCallInfo fcinfo) /* Check caller can handle a set result */ if (!rsi || !IsA(rsi, ReturnSetInfo) || (rsi->allowedModes & SFRM_Materialize) == 0) - elog(ERROR, "Set-valued function called in context that cannot accept a set"); + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("set-valued function called in context that cannot accept a set"))); rsi->returnMode = SFRM_Materialize; /* If we produced any tuples, send back the result */ @@ -447,8 +448,7 @@ plpgsql_exec_trigger(PLpgSQL_function * func, break; default: - elog(ERROR, "unknown dtype %d in plpgsql_exec_function()", - func->datums[i]->dtype); + elog(ERROR, "unrecognized dtype: %d", func->datums[i]->dtype); } } @@ -494,7 +494,7 @@ plpgsql_exec_trigger(PLpgSQL_function * func, rec_old->tupdesc = trigdata->tg_relation->rd_att; } else - elog(ERROR, "Unknown trigger action: not INSERT, DELETE, or UPDATE"); + elog(ERROR, "unrecognized trigger action: not INSERT, DELETE, or UPDATE"); /* * Assign the special tg_ variables @@ -511,7 +511,7 @@ plpgsql_exec_trigger(PLpgSQL_function * func, else if (TRIGGER_FIRED_BY_DELETE(trigdata->tg_event)) var->value = DirectFunctionCall1(textin, CStringGetDatum("DELETE")); else - elog(ERROR, "Unknown trigger action: not INSERT, DELETE, or UPDATE"); + elog(ERROR, "unrecognized trigger action: not INSERT, DELETE, or UPDATE"); var = (PLpgSQL_var *) (estate.datums[func->tg_name_varno]); var->isnull = false; @@ -527,7 +527,7 @@ plpgsql_exec_trigger(PLpgSQL_function * func, else if (TRIGGER_FIRED_AFTER(trigdata->tg_event)) var->value = DirectFunctionCall1(textin, CStringGetDatum("AFTER")); else - elog(ERROR, "Unknown trigger execution time: not BEFORE or AFTER"); + elog(ERROR, "unrecognized trigger execution time: not BEFORE or AFTER"); var = (PLpgSQL_var *) (estate.datums[func->tg_level_varno]); var->isnull = false; @@ -537,7 +537,7 @@ plpgsql_exec_trigger(PLpgSQL_function * func, else if (TRIGGER_FIRED_FOR_STATEMENT(trigdata->tg_event)) var->value = DirectFunctionCall1(textin, CStringGetDatum("STATEMENT")); else - elog(ERROR, "Unknown trigger event type: not ROW or STATEMENT"); + elog(ERROR, "unrecognized trigger event type: not ROW or STATEMENT"); var = (PLpgSQL_var *) (estate.datums[func->tg_relid_varno]); var->isnull = false; @@ -598,8 +598,7 @@ plpgsql_exec_trigger(PLpgSQL_function * func, break; default: - elog(ERROR, "unknown dtype %d in plpgsql_exec_trigger()", - func->datums[i]->dtype); + elog(ERROR, "unrecognized dtype: %d", func->datums[i]->dtype); } } @@ -617,11 +616,15 @@ plpgsql_exec_trigger(PLpgSQL_function * func, { estate.err_stmt = NULL; estate.err_text = "at END of toplevel PL block"; - elog(ERROR, "control reaches end of trigger procedure without RETURN"); + ereport(ERROR, + (errcode(ERRCODE_S_R_E_FUNCTION_EXECUTED_NO_RETURN_STATEMENT), + errmsg("control reached end of trigger procedure without RETURN"))); } if (estate.retisset) - elog(ERROR, "trigger procedure cannot return a set"); + ereport(ERROR, + (errcode(ERRCODE_DATATYPE_MISMATCH), + errmsg("trigger procedure cannot return a set"))); /* * Check that the returned tuple structure has the same attributes, @@ -639,7 +642,9 @@ plpgsql_exec_trigger(PLpgSQL_function * func, { if (!compatible_tupdesc(estate.rettupdesc, trigdata->tg_relation->rd_att)) - elog(ERROR, "returned tuple structure doesn't match table of trigger event"); + ereport(ERROR, + (errcode(ERRCODE_DATATYPE_MISMATCH), + errmsg("returned tuple structure does not match table of trigger event"))); /* Copy tuple to upper executor memory */ rettup = SPI_copytuple((HeapTuple) (estate.retval)); } @@ -758,7 +763,10 @@ exec_stmt_block(PLpgSQL_execstate * estate, PLpgSQL_stmt_block * block) var->value = (Datum) 0; var->isnull = true; if (var->notnull) - elog(ERROR, "variable '%s' declared NOT NULL cannot default to NULL", var->refname); + ereport(ERROR, + (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), + errmsg("variable \"%s\" declared NOT NULL cannot default to NULL", + var->refname))); } else { @@ -790,7 +798,8 @@ exec_stmt_block(PLpgSQL_execstate * estate, PLpgSQL_stmt_block * block) break; default: - elog(ERROR, "unknown dtype %d in exec_stmt_block()", estate->datums[n]->dtype); + elog(ERROR, "unrecognized dtype: %d", + estate->datums[n]->dtype); } } @@ -822,7 +831,7 @@ exec_stmt_block(PLpgSQL_execstate * estate, PLpgSQL_stmt_block * block) return PLPGSQL_RC_RETURN; default: - elog(ERROR, "unknown rc %d from exec_stmt()", rc); + elog(ERROR, "unrecognized rc: %d", rc); } return PLPGSQL_RC_OK; @@ -951,8 +960,7 @@ exec_stmt(PLpgSQL_execstate * estate, PLpgSQL_stmt * stmt) default: estate->err_stmt = save_estmt; - elog(ERROR, "unknown cmdtype %d in exec_stmt", - stmt->cmd_type); + elog(ERROR, "unrecognized cmdtype: %d", stmt->cmd_type); } estate->err_stmt = save_estmt; @@ -996,7 +1004,9 @@ exec_stmt_perform(PLpgSQL_execstate * estate, PLpgSQL_stmt_perform * stmt) rc = exec_run_select(estate, expr, 0, NULL); if (rc != SPI_OK_SELECT) - elog(ERROR, "query \"%s\" didn't return data", expr->query); + ereport(ERROR, + (errcode(ERRCODE_WRONG_OBJECT_TYPE), + errmsg("query \"%s\" did not return data", expr->query))); exec_set_found(estate, (estate->eval_processed != 0)); @@ -1046,8 +1056,7 @@ exec_stmt_getdiag(PLpgSQL_execstate * estate, PLpgSQL_stmt_getdiag * stmt) break; default: - - elog(ERROR, "unknown attribute request %d in get_diagnostic", + elog(ERROR, "unrecognized attribute request: %d", dtitem->item); } } @@ -1119,7 +1128,7 @@ exec_stmt_loop(PLpgSQL_execstate * estate, PLpgSQL_stmt_loop * stmt) return PLPGSQL_RC_RETURN; default: - elog(ERROR, "unknown rc %d from exec_stmts()", rc); + elog(ERROR, "unrecognized rc: %d", rc); } } @@ -1169,7 +1178,7 @@ exec_stmt_while(PLpgSQL_execstate * estate, PLpgSQL_stmt_while * stmt) return PLPGSQL_RC_RETURN; default: - elog(ERROR, "unknown rc %d from exec_stmts()", rc); + elog(ERROR, "unrecognized rc: %d", rc); } } @@ -1204,7 +1213,9 @@ exec_stmt_fori(PLpgSQL_execstate * estate, PLpgSQL_stmt_fori * stmt) var->datatype->typelem, var->datatype->atttypmod, &isnull); if (isnull) - elog(ERROR, "lower bound of FOR loop cannot be NULL"); + ereport(ERROR, + (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), + errmsg("lower bound of FOR loop cannot be NULL"))); var->value = value; var->isnull = false; exec_eval_cleanup(estate); @@ -1218,7 +1229,9 @@ exec_stmt_fori(PLpgSQL_execstate * estate, PLpgSQL_stmt_fori * stmt) var->datatype->typelem, var->datatype->atttypmod, &isnull); if (isnull) - elog(ERROR, "upper bound of FOR loop cannot be NULL"); + ereport(ERROR, + (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), + errmsg("upper bound of FOR loop cannot be NULL"))); exec_eval_cleanup(estate); /* @@ -1319,7 +1332,7 @@ exec_stmt_fors(PLpgSQL_execstate * estate, PLpgSQL_stmt_fors * stmt) else if (stmt->row != NULL) row = (PLpgSQL_row *) (estate->datums[stmt->row->rowno]); else - elog(ERROR, "unsupported target in exec_stmt_fors()"); + elog(ERROR, "unsupported target"); /* * Open the implicit cursor for the statement and fetch the initial 10 @@ -1450,7 +1463,7 @@ exec_stmt_select(PLpgSQL_execstate * estate, PLpgSQL_stmt_select * stmt) else if (stmt->row != NULL) row = (PLpgSQL_row *) (estate->datums[stmt->row->rowno]); else - elog(ERROR, "unsupported target in exec_stmt_select()"); + elog(ERROR, "unsupported target"); /* * Run the query @@ -1592,7 +1605,9 @@ exec_stmt_return_next(PLpgSQL_execstate * estate, bool free_tuple = false; if (!estate->retisset) - elog(ERROR, "Cannot use RETURN NEXT in a non-SETOF function"); + ereport(ERROR, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("cannot use RETURN NEXT in a non-SETOF function"))); if (estate->tuple_store == NULL) exec_init_tuple_store(estate); @@ -1606,9 +1621,15 @@ exec_stmt_return_next(PLpgSQL_execstate * estate, PLpgSQL_rec *rec = (PLpgSQL_rec *) (estate->datums[stmt->rec->recno]); if (!HeapTupleIsValid(rec->tup)) - elog(ERROR, "record \"%s\" is unassigned yet", rec->refname); + ereport(ERROR, + (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), + errmsg("record \"%s\" is not assigned yet", + rec->refname), + errdetail("The tuple structure of a not-yet-assigned record is indeterminate."))); if (!compatible_tupdesc(tupdesc, rec->tupdesc)) - elog(ERROR, "Wrong record type supplied in RETURN NEXT"); + ereport(ERROR, + (errcode(ERRCODE_DATATYPE_MISMATCH), + errmsg("wrong record type supplied in RETURN NEXT"))); tuple = rec->tup; } else if (stmt->row) @@ -1618,7 +1639,9 @@ exec_stmt_return_next(PLpgSQL_execstate * estate, int i; if (natts != stmt->row->nfields) - elog(ERROR, "Wrong record type supplied in RETURN NEXT"); + ereport(ERROR, + (errcode(ERRCODE_DATATYPE_MISMATCH), + errmsg("wrong record type supplied in RETURN NEXT"))); dvalues = (Datum *) palloc0(natts * sizeof(Datum)); nulls = (char *) palloc(natts * sizeof(char)); @@ -1630,7 +1653,9 @@ exec_stmt_return_next(PLpgSQL_execstate * estate, var = (PLpgSQL_var *) (estate->datums[stmt->row->varnos[i]]); if (var->datatype->typoid != tupdesc->attrs[i]->atttypid) - elog(ERROR, "Wrong record type supplied in RETURN NEXT"); + ereport(ERROR, + (errcode(ERRCODE_DATATYPE_MISMATCH), + errmsg("wrong record type supplied in RETURN NEXT"))); dvalues[i] = var->value; if (!var->isnull) nulls[i] = ' '; @@ -1650,7 +1675,9 @@ exec_stmt_return_next(PLpgSQL_execstate * estate, char nullflag; if (natts != 1) - elog(ERROR, "Wrong result type supplied in RETURN NEXT"); + ereport(ERROR, + (errcode(ERRCODE_DATATYPE_MISMATCH), + errmsg("wrong result type supplied in RETURN NEXT"))); retval = exec_eval_expr(estate, stmt->expr, @@ -1674,7 +1701,9 @@ exec_stmt_return_next(PLpgSQL_execstate * estate, } else { - elog(ERROR, "Blank RETURN NEXT not allowed"); + ereport(ERROR, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("RETURN NEXT must have a parameter"))); tuple = NULL; /* keep compiler quiet */ } @@ -1705,7 +1734,9 @@ exec_init_tuple_store(PLpgSQL_execstate * estate) if (!rsi || !IsA(rsi, ReturnSetInfo) || (rsi->allowedModes & SFRM_Materialize) == 0 || rsi->expectedDesc == NULL) - elog(ERROR, "Set-valued function called in context that cannot accept a set"); + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("set-valued function called in context that cannot accept a set"))); estate->tuple_store_cxt = rsi->econtext->ecxt_per_query_memory; @@ -1717,8 +1748,7 @@ exec_init_tuple_store(PLpgSQL_execstate * estate) } /* ---------- - * exec_stmt_raise Build a message and throw it with - * elog() + * exec_stmt_raise Build a message and throw it with elog() * ---------- */ static int @@ -1741,23 +1771,20 @@ exec_stmt_raise(PLpgSQL_execstate * estate, PLpgSQL_stmt_raise * stmt) for (cp = stmt->message; *cp; cp++) { /* - * Occurences of a single % are replaced by the next arguments - * external representation. Double %'s are left as is so elog() - * will also don't touch them. + * Occurences of a single % are replaced by the next argument's + * external representation. Double %'s are converted to one %. */ if ((c[0] = *cp) == '%') { cp++; if (*cp == '%') { - plpgsql_dstring_append(&ds, c); plpgsql_dstring_append(&ds, c); continue; } cp--; if (pidx >= stmt->nparams) { - plpgsql_dstring_append(&ds, c); plpgsql_dstring_append(&ds, c); continue; } @@ -1774,7 +1801,7 @@ exec_stmt_raise(PLpgSQL_execstate * estate, PLpgSQL_stmt_raise * stmt) ObjectIdGetDatum(paramtypeid), 0, 0, 0); if (!HeapTupleIsValid(typetup)) - elog(ERROR, "cache lookup for type %u failed", + elog(ERROR, "cache lookup failed for type %u", paramtypeid); typeStruct = (Form_pg_type) GETSTRUCT(typetup); @@ -1792,7 +1819,9 @@ exec_stmt_raise(PLpgSQL_execstate * estate, PLpgSQL_stmt_raise * stmt) /* * Occurrences of single ' are removed. double ' are reduced to - * single ones. + * single ones. We must do this because the parameter stored + * by the grammar is the raw T_STRING input literal, rather than + * the de-lexed string as you might expect ... */ if (*cp == '\'') { @@ -1998,8 +2027,10 @@ exec_stmt_execsql(PLpgSQL_execstate * estate, break; case SPI_OK_SELECT: - elog(ERROR, "SELECT query has no destination for result data." - "\n\tIf you want to discard the results, use PERFORM instead."); + ereport(ERROR, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("SELECT query has no destination for result data"), + errhint("If you want to discard the results, use PERFORM instead."))); default: elog(ERROR, "error executing query \"%s\"", expr->query); @@ -2046,7 +2077,9 @@ exec_stmt_dynexecute(PLpgSQL_execstate * estate, */ query = exec_eval_expr(estate, stmt->query, &isnull, &restype); if (isnull) - elog(ERROR, "cannot EXECUTE NULL query"); + ereport(ERROR, + (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), + errmsg("cannot EXECUTE a null querystring"))); /* * Get the C-String representation. @@ -2055,7 +2088,7 @@ exec_stmt_dynexecute(PLpgSQL_execstate * estate, ObjectIdGetDatum(restype), 0, 0, 0); if (!HeapTupleIsValid(typetup)) - elog(ERROR, "cache lookup for type %u failed", restype); + elog(ERROR, "cache lookup failed for type %u", restype); typeStruct = (Form_pg_type) GETSTRUCT(typetup); fmgr_info(typeStruct->typoutput, &finfo_output); @@ -2109,12 +2142,14 @@ exec_stmt_dynexecute(PLpgSQL_execstate * estate, if (!isspace((unsigned char) *ptr)) break; if (*ptr == 'S' || *ptr == 's') - elog(ERROR, "EXECUTE of SELECT ... INTO is not implemented yet"); + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("EXECUTE of SELECT ... INTO is not implemented yet"))); break; } default: - elog(ERROR, "unexpected error %d in EXECUTE of query '%s'", + elog(ERROR, "unexpected error %d in EXECUTE of query \"%s\"", exec_res, querystr); break; } @@ -2166,7 +2201,7 @@ exec_stmt_dynfors(PLpgSQL_execstate * estate, PLpgSQL_stmt_dynfors * stmt) else if (stmt->row != NULL) row = (PLpgSQL_row *) (estate->datums[stmt->row->rowno]); else - elog(ERROR, "unsupported target in exec_stmt_dynfors()"); + elog(ERROR, "unsupported target"); /* * Evaluate the string expression after the EXECUTE keyword. It's @@ -2174,7 +2209,9 @@ exec_stmt_dynfors(PLpgSQL_execstate * estate, PLpgSQL_stmt_dynfors * stmt) */ query = exec_eval_expr(estate, stmt->query, &isnull, &restype); if (isnull) - elog(ERROR, "cannot EXECUTE NULL-query"); + ereport(ERROR, + (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), + errmsg("cannot EXECUTE a null querystring"))); /* * Get the C-String representation. @@ -2183,7 +2220,7 @@ exec_stmt_dynfors(PLpgSQL_execstate * estate, PLpgSQL_stmt_dynfors * stmt) ObjectIdGetDatum(restype), 0, 0, 0); if (!HeapTupleIsValid(typetup)) - elog(ERROR, "cache lookup for type %u failed", restype); + elog(ERROR, "cache lookup failed for type %u", restype); typeStruct = (Form_pg_type) GETSTRUCT(typetup); fmgr_info(typeStruct->typoutput, &finfo_output); @@ -2335,7 +2372,9 @@ exec_stmt_open(PLpgSQL_execstate * estate, PLpgSQL_stmt_open * stmt) { curname = DatumGetCString(DirectFunctionCall1(textout, curvar->value)); if (SPI_cursor_find(curname) != NULL) - elog(ERROR, "cursor \"%s\" already in use", curname); + ereport(ERROR, + (errcode(ERRCODE_DUPLICATE_CURSOR), + errmsg("cursor \"%s\" already in use", curname))); } /* ---------- @@ -2377,7 +2416,9 @@ exec_stmt_open(PLpgSQL_execstate * estate, PLpgSQL_stmt_open * stmt) */ queryD = exec_eval_expr(estate, stmt->dynquery, &isnull, &restype); if (isnull) - elog(ERROR, "cannot EXECUTE NULL query"); + ereport(ERROR, + (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), + errmsg("cannot EXECUTE a null querystring"))); /* ---------- * Get the C-String representation. @@ -2387,7 +2428,7 @@ exec_stmt_open(PLpgSQL_execstate * estate, PLpgSQL_stmt_open * stmt) ObjectIdGetDatum(restype), 0, 0, 0); if (!HeapTupleIsValid(typetup)) - elog(ERROR, "cache lookup for type %u failed", restype); + elog(ERROR, "cache lookup failed for type %u", restype); typeStruct = (Form_pg_type) GETSTRUCT(typetup); fmgr_info(typeStruct->typoutput, &finfo_output); @@ -2409,7 +2450,7 @@ exec_stmt_open(PLpgSQL_execstate * estate, PLpgSQL_stmt_open * stmt) querystr); portal = SPI_cursor_open(curname, curplan, NULL, NULL); if (portal == NULL) - elog(ERROR, "Failed to open cursor"); + elog(ERROR, "failed to open cursor"); pfree(querystr); SPI_freeplan(curplan); @@ -2446,7 +2487,9 @@ exec_stmt_open(PLpgSQL_execstate * estate, PLpgSQL_stmt_open * stmt) PLpgSQL_stmt_select set_args; if (curvar->cursor_explicit_argrow < 0) - elog(ERROR, "arguments given for cursor without arguments"); + ereport(ERROR, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("arguments given for cursor without arguments"))); memset(&set_args, 0, sizeof(set_args)); set_args.cmd_type = PLPGSQL_STMT_SELECT; @@ -2461,7 +2504,9 @@ exec_stmt_open(PLpgSQL_execstate * estate, PLpgSQL_stmt_open * stmt) else { if (curvar->cursor_explicit_argrow >= 0) - elog(ERROR, "arguments required for cursor"); + ereport(ERROR, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("arguments required for cursor"))); } query = curvar->cursor_explicit_expr; @@ -2498,7 +2543,7 @@ exec_stmt_open(PLpgSQL_execstate * estate, PLpgSQL_stmt_open * stmt) */ portal = SPI_cursor_open(curname, query->plan, values, nulls); if (portal == NULL) - elog(ERROR, "Failed to open cursor"); + elog(ERROR, "failed to open cursor"); pfree(values); pfree(nulls); @@ -2541,12 +2586,16 @@ exec_stmt_fetch(PLpgSQL_execstate * estate, PLpgSQL_stmt_fetch * stmt) */ curvar = (PLpgSQL_var *) (estate->datums[stmt->curvar]); if (curvar->isnull) - elog(ERROR, "cursor variable \"%s\" is NULL", curvar->refname); + ereport(ERROR, + (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), + errmsg("cursor variable \"%s\" is NULL", curvar->refname))); curname = DatumGetCString(DirectFunctionCall1(textout, curvar->value)); portal = SPI_cursor_find(curname); if (portal == NULL) - elog(ERROR, "cursor \"%s\" is invalid", curname); + ereport(ERROR, + (errcode(ERRCODE_UNDEFINED_CURSOR), + errmsg("cursor \"%s\" does not exist", curname))); pfree(curname); /* ---------- @@ -2558,7 +2607,7 @@ exec_stmt_fetch(PLpgSQL_execstate * estate, PLpgSQL_stmt_fetch * stmt) else if (stmt->row != NULL) row = (PLpgSQL_row *) (estate->datums[stmt->row->rowno]); else - elog(ERROR, "unsupported target in exec_stmt_fetch()"); + elog(ERROR, "unsupported target"); /* ---------- * Fetch 1 tuple from the cursor @@ -2606,12 +2655,16 @@ exec_stmt_close(PLpgSQL_execstate * estate, PLpgSQL_stmt_close * stmt) */ curvar = (PLpgSQL_var *) (estate->datums[stmt->curvar]); if (curvar->isnull) - elog(ERROR, "cursor variable \"%s\" is NULL", curvar->refname); + ereport(ERROR, + (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), + errmsg("cursor variable \"%s\" is NULL", curvar->refname))); curname = DatumGetCString(DirectFunctionCall1(textout, curvar->value)); portal = SPI_cursor_find(curname); if (portal == NULL) - elog(ERROR, "cursor \"%s\" is invalid", curname); + ereport(ERROR, + (errcode(ERRCODE_UNDEFINED_CURSOR), + errmsg("cursor \"%s\" does not exist", curname))); pfree(curname); /* ---------- @@ -2703,7 +2756,10 @@ exec_assign_value(PLpgSQL_execstate * estate, isNull); if (*isNull && var->notnull) - elog(ERROR, "NULL assignment to variable '%s' declared NOT NULL", var->refname); + ereport(ERROR, + (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), + errmsg("NULL cannot be assigned to variable \"%s\" declared NOT NULL", + var->refname))); /* * If type is by-reference, make sure we have a freshly @@ -2741,7 +2797,11 @@ exec_assign_value(PLpgSQL_execstate * estate, * structure. */ if (!HeapTupleIsValid(rec->tup)) - elog(ERROR, "record \"%s\" is unassigned yet - don't know its tuple structure", rec->refname); + ereport(ERROR, + (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), + errmsg("record \"%s\" is not assigned yet", + rec->refname), + errdetail("The tuple structure of a not-yet-assigned record is indeterminate."))); /* * Get the number of the records field to change and the @@ -2749,7 +2809,10 @@ exec_assign_value(PLpgSQL_execstate * estate, */ fno = SPI_fnumber(rec->tupdesc, recfield->fieldname); if (fno == SPI_ERROR_NOATTRIBUTE) - elog(ERROR, "record \"%s\" has no field named \"%s\"", rec->refname, recfield->fieldname); + ereport(ERROR, + (errcode(ERRCODE_UNDEFINED_COLUMN), + errmsg("record \"%s\" has no field \"%s\"", + rec->refname, recfield->fieldname))); fno--; natts = rec->tupdesc->natts; @@ -2835,7 +2898,10 @@ exec_assign_value(PLpgSQL_execstate * estate, PLpgSQL_arrayelem *arrayelem = (PLpgSQL_arrayelem *) target; if (nsubscripts >= MAXDIM) - elog(ERROR, "Too many subscripts"); + ereport(ERROR, + (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), + errmsg("number of array dimensions exceeds the maximum allowed, %d", + MAXDIM))); subscripts[nsubscripts++] = arrayelem->subscript; target = estate->datums[arrayelem->arrayparentno]; } while (target->dtype == PLPGSQL_DTYPE_ARRAYELEM); @@ -2846,7 +2912,9 @@ exec_assign_value(PLpgSQL_execstate * estate, getTypeInputInfo(arraytypeid, &arrayInputFn, &arrayelemtypeid); if (!OidIsValid(arrayelemtypeid)) - elog(ERROR, "Subscripted item is not an array"); + ereport(ERROR, + (errcode(ERRCODE_DATATYPE_MISMATCH), + errmsg("subscripted object is not an array"))); /* Evaluate the subscripts, switch into left-to-right order */ havenullsubscript = false; @@ -2916,8 +2984,7 @@ exec_assign_value(PLpgSQL_execstate * estate, break; default: - elog(ERROR, "unknown dtype %d in exec_assign_value()", - target->dtype); + elog(ERROR, "unrecognized dtype: %d", target->dtype); } } @@ -2957,24 +3024,34 @@ exec_eval_datum(PLpgSQL_execstate *estate, *value = var->value; *isnull = var->isnull; if (expectedtypeid != InvalidOid && expectedtypeid != *typeid) - elog(ERROR, "type of %s doesn't match that when preparing the plan", - var->refname); + ereport(ERROR, + (errcode(ERRCODE_DATATYPE_MISMATCH), + errmsg("type of \"%s\" does not match that when preparing the plan", + var->refname))); break; case PLPGSQL_DTYPE_RECFIELD: recfield = (PLpgSQL_recfield *) datum; rec = (PLpgSQL_rec *) (estate->datums[recfield->recparentno]); if (!HeapTupleIsValid(rec->tup)) - elog(ERROR, "record \"%s\" is unassigned yet", rec->refname); + ereport(ERROR, + (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), + errmsg("record \"%s\" is not assigned yet", + rec->refname), + errdetail("The tuple structure of a not-yet-assigned record is indeterminate."))); fno = SPI_fnumber(rec->tupdesc, recfield->fieldname); if (fno == SPI_ERROR_NOATTRIBUTE) - elog(ERROR, "record \"%s\" has no field named \"%s\"", - rec->refname, recfield->fieldname); + ereport(ERROR, + (errcode(ERRCODE_UNDEFINED_COLUMN), + errmsg("record \"%s\" has no field \"%s\"", + rec->refname, recfield->fieldname))); *typeid = SPI_gettypeid(rec->tupdesc, fno); *value = SPI_getbinval(rec->tup, rec->tupdesc, fno, isnull); if (expectedtypeid != InvalidOid && expectedtypeid != *typeid) - elog(ERROR, "type of %s.%s doesn't match that when preparing the plan", - rec->refname, recfield->fieldname); + ereport(ERROR, + (errcode(ERRCODE_DATATYPE_MISMATCH), + errmsg("type of \"%s.%s\" does not match that when preparing the plan", + rec->refname, recfield->fieldname))); break; case PLPGSQL_DTYPE_TRIGARG: @@ -2992,13 +3069,14 @@ exec_eval_datum(PLpgSQL_execstate *estate, *isnull = false; } if (expectedtypeid != InvalidOid && expectedtypeid != *typeid) - elog(ERROR, "type of tgargv[%d] doesn't match that when preparing the plan", - tgargno); + ereport(ERROR, + (errcode(ERRCODE_DATATYPE_MISMATCH), + errmsg("type of tgargv[%d] does not match that when preparing the plan", + tgargno))); break; default: - elog(ERROR, "unknown datum dtype %d in exec_eval_datum()", - datum->dtype); + elog(ERROR, "unrecognized dtype: %d", datum->dtype); } } @@ -3062,7 +3140,9 @@ exec_eval_expr(PLpgSQL_execstate * estate, rc = exec_run_select(estate, expr, 2, NULL); if (rc != SPI_OK_SELECT) - elog(ERROR, "query \"%s\" didn't return data", expr->query); + ereport(ERROR, + (errcode(ERRCODE_WRONG_OBJECT_TYPE), + errmsg("query \"%s\" did not return data", expr->query))); /* * If there are no rows selected, the result is NULL. @@ -3077,10 +3157,15 @@ exec_eval_expr(PLpgSQL_execstate * estate, * Check that the expression returned one single Datum */ if (estate->eval_processed > 1) - elog(ERROR, "query \"%s\" returned more than one row", expr->query); + ereport(ERROR, + (errcode(ERRCODE_CARDINALITY_VIOLATION), + errmsg("query \"%s\" returned more than one row", + expr->query))); if (estate->eval_tuptable->tupdesc->natts != 1) - elog(ERROR, "query \"%s\" returned %d columns", expr->query, - estate->eval_tuptable->tupdesc->natts); + ereport(ERROR, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("query \"%s\" returned %d columns", expr->query, + estate->eval_tuptable->tupdesc->natts))); /* * Return the result and its type @@ -3149,7 +3234,9 @@ exec_run_select(PLpgSQL_execstate * estate, */ rc = SPI_execp(expr->plan, values, nulls, maxtuples); if (rc != SPI_OK_SELECT) - elog(ERROR, "query \"%s\" isn't a SELECT", expr->query); + ereport(ERROR, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("query \"%s\" is not a SELECT", expr->query))); /* Save query results for eventual cleanup */ Assert(estate->eval_tuptable == NULL); @@ -3356,7 +3443,7 @@ exec_move_row(PLpgSQL_execstate * estate, return; } - elog(ERROR, "unsupported target in exec_move_row()"); + elog(ERROR, "unsupported target"); } @@ -3389,7 +3476,7 @@ exec_cast_value(Datum value, Oid valtype, ObjectIdGetDatum(valtype), 0, 0, 0); if (!HeapTupleIsValid(typetup)) - elog(ERROR, "cache lookup for type %u failed", valtype); + elog(ERROR, "cache lookup failed for type %u", valtype); typeStruct = (Form_pg_type) GETSTRUCT(typetup); fmgr_info(typeStruct->typoutput, &finfo_output); diff --git a/src/pl/plpgsql/src/pl_funcs.c b/src/pl/plpgsql/src/pl_funcs.c index b18f584f66..632dd36e81 100644 --- a/src/pl/plpgsql/src/pl_funcs.c +++ b/src/pl/plpgsql/src/pl_funcs.c @@ -3,7 +3,7 @@ * procedural language * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_funcs.c,v 1.26 2003/05/23 04:08:34 tgl Exp $ + * $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_funcs.c,v 1.27 2003/07/25 23:37:29 tgl Exp $ * * This software is copyrighted by Jan Wieck - Hamburg. * @@ -313,7 +313,10 @@ plpgsql_ns_rename(char *oldname, char *newname) } } - elog(ERROR, "there is no variable '%s' in the current block", oldname); + ereport(ERROR, + (errcode(ERRCODE_UNDEFINED_OBJECT), + errmsg("there is no variable \"%s\" in the current block", + oldname))); } @@ -366,7 +369,9 @@ plpgsql_convert_ident(const char *s, char **output, int numidents) *cp++ = *s++; } if (*s != '"') /* should not happen if lexer checked */ - elog(ERROR, "unterminated \" in name: %s", sstart); + ereport(ERROR, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("unterminated \" in name: %s", sstart))); s++; } else @@ -403,8 +408,10 @@ plpgsql_convert_ident(const char *s, char **output, int numidents) if (identctr < numidents) output[identctr++] = curident; else - elog(ERROR, "Qualified identifier cannot be used here: %s", - sstart); + ereport(ERROR, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("qualified identifier cannot be used here: %s", + sstart))); /* If not done, skip whitespace, dot, whitespace */ if (*s) @@ -412,16 +419,16 @@ plpgsql_convert_ident(const char *s, char **output, int numidents) while (*s && isspace((unsigned char) *s)) s++; if (*s++ != '.') - elog(ERROR, "Expected dot between identifiers: %s", sstart); + elog(ERROR, "expected dot between identifiers: %s", sstart); while (*s && isspace((unsigned char) *s)) s++; if (*s == '\0') - elog(ERROR, "Expected another identifier: %s", sstart); + elog(ERROR, "expected another identifier: %s", sstart); } } if (identctr != numidents) - elog(ERROR, "Improperly qualified identifier: %s", + elog(ERROR, "improperly qualified identifier: %s", sstart); } @@ -586,7 +593,7 @@ dump_stmt(PLpgSQL_stmt * stmt) dump_perform((PLpgSQL_stmt_perform *) stmt); break; default: - elog(ERROR, "plpgsql_dump: unknown cmd_type %d\n", stmt->cmd_type); + elog(ERROR, "unknown cmd_type: %d", stmt->cmd_type); break; } } diff --git a/src/pl/plpgsql/src/pl_handler.c b/src/pl/plpgsql/src/pl_handler.c index 592877fe52..81d08ac512 100644 --- a/src/pl/plpgsql/src/pl_handler.c +++ b/src/pl/plpgsql/src/pl_handler.c @@ -3,7 +3,7 @@ * procedural language * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_handler.c,v 1.13 2003/07/01 21:47:09 tgl Exp $ + * $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_handler.c,v 1.14 2003/07/25 23:37:29 tgl Exp $ * * This software is copyrighted by Jan Wieck - Hamburg. * @@ -65,7 +65,7 @@ plpgsql_call_handler(PG_FUNCTION_ARGS) * Connect to SPI manager */ if (SPI_connect() != SPI_OK_CONNECT) - elog(ERROR, "plpgsql: cannot connect to SPI manager"); + elog(ERROR, "could not connect to SPI manager"); /* Find or compile the function */ func = plpgsql_compile(fcinfo); @@ -84,7 +84,7 @@ plpgsql_call_handler(PG_FUNCTION_ARGS) * Disconnect from SPI manager */ if (SPI_finish() != SPI_OK_FINISH) - elog(ERROR, "plpgsql: SPI_finish() failed"); + elog(ERROR, "SPI_finish() failed"); return retval; } diff --git a/src/pl/plpgsql/src/scan.l b/src/pl/plpgsql/src/scan.l index 2203cdd6b4..68715df9ed 100644 --- a/src/pl/plpgsql/src/scan.l +++ b/src/pl/plpgsql/src/scan.l @@ -4,7 +4,7 @@ * procedural language * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/pl/plpgsql/src/Attic/scan.l,v 1.28 2003/06/19 23:22:40 tgl Exp $ + * $Header: /cvsroot/pgsql/src/pl/plpgsql/src/Attic/scan.l,v 1.29 2003/07/25 23:37:29 tgl Exp $ * * This software is copyrighted by Jan Wieck - Hamburg. * @@ -228,7 +228,9 @@ dump { return O_DUMP; } \". { plpgsql_error_lineno = plpgsql_scanner_lineno(); - elog(ERROR, "unterminated quoted identifier"); + ereport(ERROR, + (errcode(ERRCODE_DATATYPE_MISMATCH), + errmsg("unterminated quoted identifier"))); } /* ---------- @@ -251,7 +253,9 @@ dump { return O_DUMP; } . ; <> { plpgsql_error_lineno = start_lineno; - elog(ERROR, "unterminated comment"); + ereport(ERROR, + (errcode(ERRCODE_DATATYPE_MISMATCH), + errmsg("unterminated comment"))); } /* ---------- @@ -277,7 +281,9 @@ dump { return O_DUMP; } } <> { plpgsql_error_lineno = start_lineno; - elog(ERROR, "unterminated string"); + ereport(ERROR, + (errcode(ERRCODE_DATATYPE_MISMATCH), + errmsg("unterminated string"))); } [^'\\]* { } @@ -344,7 +350,7 @@ void plpgsql_push_back_token(int token) { if (have_pushback_token) - elog(ERROR, "plpgsql_push_back_token: can't push back multiple tokens"); + elog(ERROR, "cannot push back multiple tokens"); pushback_token = token; have_pushback_token = true; } diff --git a/src/pl/plpython/plpython.c b/src/pl/plpython/plpython.c index 3bc5d73b33..2a4c45e6e5 100644 --- a/src/pl/plpython/plpython.c +++ b/src/pl/plpython/plpython.c @@ -29,7 +29,7 @@ * MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/pl/plpython/plpython.c,v 1.34 2003/06/25 01:18:58 momjian Exp $ + * $Header: /cvsroot/pgsql/src/pl/plpython/plpython.c,v 1.35 2003/07/25 23:37:30 tgl Exp $ * ********************************************************************* */ @@ -333,7 +333,7 @@ plpython_call_handler(PG_FUNCTION_ARGS) PLy_init_all(); if (SPI_connect() != SPI_OK_CONNECT) - elog(ERROR, "plpython: Unable to connect to SPI manager"); + elog(ERROR, "could not connect to SPI manager"); CALL_LEVEL_INC(); is_trigger = CALLED_AS_TRIGGER(fcinfo); @@ -420,13 +420,13 @@ PLy_trigger_handler(FunctionCallInfo fcinfo, PLyProcedure * proc) * Disconnect from SPI manager */ if (SPI_finish() != SPI_OK_FINISH) - elog(ERROR, "plpython: SPI_finish failed"); + elog(ERROR, "SPI_finish failed"); if (plrv == NULL) - elog(FATAL, "Aiieee, PLy_procedure_call returned NULL"); + elog(FATAL, "PLy_procedure_call returned NULL"); if (PLy_restart_in_progress) - elog(FATAL, "Aiieee, restart in progress not expected"); + elog(FATAL, "restart in progress not expected"); /* * return of None means we're happy with the tuple @@ -436,7 +436,7 @@ PLy_trigger_handler(FunctionCallInfo fcinfo, PLyProcedure * proc) char *srv; if (!PyString_Check(plrv)) - elog(ERROR, "plpython: Expected trigger to return None or a String"); + elog(ERROR, "expected trigger to return None or a String"); srv = PyString_AsString(plrv); if (strcasecmp(srv, "SKIP") == 0) @@ -449,7 +449,7 @@ PLy_trigger_handler(FunctionCallInfo fcinfo, PLyProcedure * proc) (TRIGGER_FIRED_BY_UPDATE(tdata->tg_event))) rv = PLy_modify_tuple(proc, plargs, tdata, rv); else - elog(WARNING, "plpython: Ignoring modified tuple in DELETE trigger"); + elog(WARNING, "ignoring modified tuple in DELETE trigger"); } else if (strcasecmp(srv, "OK")) { @@ -458,7 +458,7 @@ PLy_trigger_handler(FunctionCallInfo fcinfo, PLyProcedure * proc) * surprising thing since i've written no documentation, so * accept a belated OK */ - elog(ERROR, "plpython: Expected return to be 'SKIP' or 'MODIFY'"); + elog(ERROR, "expected return to be \"SKIP\" or \"MODIFY\""); } } @@ -520,16 +520,16 @@ PLy_modify_tuple(PLyProcedure * proc, PyObject * pltd, TriggerData *tdata, } if ((plntup = PyDict_GetItemString(pltd, "new")) == NULL) - elog(ERROR, "plpython: TD[\"new\"] deleted, unable to modify tuple"); + elog(ERROR, "TD[\"new\"] deleted, unable to modify tuple"); if (!PyDict_Check(plntup)) - elog(ERROR, "plpython: TD[\"new\"] is not a dictionary object"); + elog(ERROR, "TD[\"new\"] is not a dictionary object"); Py_INCREF(plntup); plkeys = PyDict_Keys(plntup); natts = PyList_Size(plkeys); if (natts != proc->result.out.r.natts) - elog(ERROR, "plpython: TD[\"new\"] has an incorrect number of keys."); + elog(ERROR, "TD[\"new\"] has an incorrect number of keys"); modattrs = palloc(natts * sizeof(int)); modvalues = palloc(natts * sizeof(Datum)); @@ -550,17 +550,17 @@ PLy_modify_tuple(PLyProcedure * proc, PyObject * pltd, TriggerData *tdata, platt = PyList_GetItem(plkeys, j); if (!PyString_Check(platt)) - elog(ERROR, "plpython: attribute is not a string"); + elog(ERROR, "attribute is not a string"); attn = modattrs[j] = SPI_fnumber(tupdesc, PyString_AsString(platt)); if (attn == SPI_ERROR_NOATTRIBUTE) - elog(ERROR, "plpython: invalid attribute `%s' in tuple.", + elog(ERROR, "invalid attribute \"%s\" in tuple", PyString_AsString(platt)); atti = attn - 1; plval = PyDict_GetItem(plntup, platt); if (plval == NULL) - elog(FATAL, "plpython: interpreter is probably corrupted"); + elog(FATAL, "python interpreter is probably corrupted"); Py_INCREF(plval); @@ -594,7 +594,7 @@ PLy_modify_tuple(PLyProcedure * proc, PyObject * pltd, TriggerData *tdata, pfree(modnulls); if (rtup == NULL) - elog(ERROR, "plpython: SPI_modifytuple failed -- error %d", SPI_result); + elog(ERROR, "SPI_modifytuple failed -- error %d", SPI_result); Py_DECREF(plntup); Py_DECREF(plkeys); @@ -636,7 +636,7 @@ PLy_trigger_build_args(FunctionCallInfo fcinfo, PLyProcedure * proc, HeapTuple * pltdata = PyDict_New(); if (!pltdata) - PLy_elog(ERROR, "Unable to build arguments for trigger procedure"); + PLy_elog(ERROR, "could not build arguments for trigger procedure"); pltname = PyString_FromString(tdata->tg_trigger->tgname); PyDict_SetItemString(pltdata, "name", pltname); @@ -786,14 +786,14 @@ PLy_function_handler(FunctionCallInfo fcinfo, PLyProcedure * proc) * it). */ if (SPI_finish() != SPI_OK_FINISH) - elog(ERROR, "plpython: SPI_finish failed"); + elog(ERROR, "SPI_finish failed"); if (plrv == NULL) { - elog(FATAL, "Aiieee, PLy_procedure_call returned NULL"); + elog(FATAL, "PLy_procedure_call returned NULL"); #ifdef NOT_USED if (!PLy_restart_in_progress) - PLy_elog(ERROR, "plpython: Function \"%s\" failed.", proc->proname); + PLy_elog(ERROR, "function \"%s\" failed", proc->proname); /* * FIXME is this dead code? i'm pretty sure it is for unnested @@ -853,7 +853,7 @@ PLy_procedure_call(PLyProcedure * proc, char *kargs, PyObject * vargs) { Py_XDECREF(rv); if (!PLy_restart_in_progress) - PLy_elog(ERROR, "Call of function `%s' failed.", proc->proname); + PLy_elog(ERROR, "function \"%s\" failed", proc->proname); RAISE_EXC(1); } @@ -951,13 +951,13 @@ PLy_procedure_get(FunctionCallInfo fcinfo, bool is_trigger) ObjectIdGetDatum(fn_oid), 0, 0, 0); if (!HeapTupleIsValid(procTup)) - elog(ERROR, "plpython: cache lookup for procedure %u failed", fn_oid); + elog(ERROR, "cache lookup failed for function %u", fn_oid); rv = snprintf(key, sizeof(key), "%u%s", fn_oid, is_trigger ? "_trigger" : ""); if ((rv >= sizeof(key)) || (rv < 0)) - elog(FATAL, "plpython: Buffer overrun in %s:%d", __FILE__, __LINE__); + elog(ERROR, "key too long"); plproc = PyDict_GetItemString(PLy_procedure_cache, key); @@ -965,13 +965,13 @@ PLy_procedure_get(FunctionCallInfo fcinfo, bool is_trigger) { Py_INCREF(plproc); if (!PyCObject_Check(plproc)) - elog(FATAL, "plpython: Expected a PyCObject, didn't get one"); + elog(FATAL, "expected a PyCObject, didn't get one"); mark(); proc = PyCObject_AsVoidPtr(plproc); if (proc->me != plproc) - elog(FATAL, "plpython: Aiieee, proc->me != plproc"); + elog(FATAL, "proc->me != plproc"); /* did we find an up-to-date cache entry? */ if (proc->fn_xmin != HeapTupleHeaderGetXmin(procTup->t_data) || proc->fn_cmin != HeapTupleHeaderGetCmin(procTup->t_data)) @@ -1013,7 +1013,7 @@ PLy_procedure_create(FunctionCallInfo fcinfo, bool is_trigger, fcinfo->flinfo->fn_oid, is_trigger ? "_trigger" : ""); if ((rv >= sizeof(procName)) || (rv < 0)) - elog(FATAL, "plpython: Procedure name would overrun buffer"); + elog(ERROR, "procedure name would overrun buffer"); proc = PLy_malloc(sizeof(PLyProcedure)); proc->proname = PLy_malloc(strlen(NameStr(procStruct->proname)) + 1); @@ -1047,19 +1047,21 @@ PLy_procedure_create(FunctionCallInfo fcinfo, bool is_trigger, { HeapTuple rvTypeTup; Form_pg_type rvTypeStruct; - Datum rvDatum; - rvDatum = ObjectIdGetDatum(procStruct->prorettype); - rvTypeTup = SearchSysCache(TYPEOID, rvDatum, 0, 0, 0); + rvTypeTup = SearchSysCache(TYPEOID, + ObjectIdGetDatum(procStruct->prorettype), + 0, 0, 0); if (!HeapTupleIsValid(rvTypeTup)) - elog(ERROR, "plpython: cache lookup for type \"%u\" failed", + elog(ERROR, "cache lookup failed for type %u", procStruct->prorettype); rvTypeStruct = (Form_pg_type) GETSTRUCT(rvTypeTup); if (rvTypeStruct->typrelid == InvalidOid) PLy_output_datum_func(&proc->result, rvTypeStruct); else - elog(ERROR, "plpython: tuple return types not supported, yet"); + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("tuple return types are not supported yet"))); ReleaseSysCache(rvTypeTup); } @@ -1084,12 +1086,12 @@ PLy_procedure_create(FunctionCallInfo fcinfo, bool is_trigger, { HeapTuple argTypeTup; Form_pg_type argTypeStruct; - Datum argDatum; - argDatum = ObjectIdGetDatum(procStruct->proargtypes[i]); - argTypeTup = SearchSysCache(TYPEOID, argDatum, 0, 0, 0); + argTypeTup = SearchSysCache(TYPEOID, + ObjectIdGetDatum(procStruct->proargtypes[i]), + 0, 0, 0); if (!HeapTupleIsValid(argTypeTup)) - elog(ERROR, "plpython: cache lookup for type \"%u\" failed", + elog(ERROR, "cache lookup failed for type %u", procStruct->proargtypes[i]); argTypeStruct = (Form_pg_type) GETSTRUCT(argTypeTup); @@ -1164,7 +1166,7 @@ PLy_procedure_compile(PLyProcedure * proc, const char *src) */ clen = snprintf(call, sizeof(call), "%s()", proc->pyname); if ((clen < 0) || (clen >= sizeof(call))) - elog(ERROR, "plpython: string would overflow buffer."); + elog(ERROR, "string would overflow buffer"); proc->code = Py_CompileString(call, "", Py_eval_input); if ((proc->code != NULL) && (!PyErr_Occurred())) return; @@ -1172,7 +1174,7 @@ PLy_procedure_compile(PLyProcedure * proc, const char *src) else Py_XDECREF(crv); - PLy_elog(ERROR, "Unable to compile function %s", proc->proname); + PLy_elog(ERROR, "could not compile function \"%s\"", proc->proname); } char * @@ -1193,8 +1195,7 @@ PLy_procedure_munge_source(const char *name, const char *src) mrc = PLy_malloc(mlen); plen = snprintf(mrc, mlen, "def %s():\n\t", name); - if ((plen < 0) || (plen >= mlen)) - elog(FATAL, "Aiieee, impossible buffer overrun (or snprintf failure)"); + Assert(plen >= 0 && plen < mlen); sp = src; mp = mrc + plen; @@ -1214,7 +1215,7 @@ PLy_procedure_munge_source(const char *name, const char *src) *mp = '\0'; if (mp > (mrc + mlen)) - elog(FATAL, "plpython: Buffer overrun in PLy_munge_source"); + elog(FATAL, "buffer overrun in PLy_munge_source"); return mrc; } @@ -1253,12 +1254,11 @@ void PLy_input_tuple_funcs(PLyTypeInfo * arg, TupleDesc desc) { int i; - Datum datum; enter(); if (arg->is_rel == 0) - elog(FATAL, "plpython: PLyTypeInfo struct is initialized for a Datum"); + elog(ERROR, "PLyTypeInfo struct is initialized for a Datum"); arg->is_rel = 1; arg->in.r.natts = desc->natts; @@ -1269,16 +1269,12 @@ PLy_input_tuple_funcs(PLyTypeInfo * arg, TupleDesc desc) HeapTuple typeTup; Form_pg_type typeStruct; - datum = ObjectIdGetDatum(desc->attrs[i]->atttypid); - typeTup = SearchSysCache(TYPEOID, datum, 0, 0, 0); + typeTup = SearchSysCache(TYPEOID, + ObjectIdGetDatum(desc->attrs[i]->atttypid), + 0, 0, 0); if (!HeapTupleIsValid(typeTup)) - { - char *attname = NameStr(desc->attrs[i]->attname); - - elog(ERROR, "plpython: Cache lookup for attribute `%s' type `%u' failed", - attname, desc->attrs[i]->atttypid); - } - + elog(ERROR, "cache lookup failed for type %u", + desc->attrs[i]->atttypid); typeStruct = (Form_pg_type) GETSTRUCT(typeTup); PLy_input_datum_func2(&(arg->in.r.atts[i]), @@ -1293,12 +1289,11 @@ void PLy_output_tuple_funcs(PLyTypeInfo * arg, TupleDesc desc) { int i; - Datum datum; enter(); if (arg->is_rel == 0) - elog(FATAL, "plpython: PLyTypeInfo struct is initialized for a Datum"); + elog(ERROR, "PLyTypeInfo struct is initialized for a Datum"); arg->is_rel = 1; arg->out.r.natts = desc->natts; @@ -1309,16 +1304,12 @@ PLy_output_tuple_funcs(PLyTypeInfo * arg, TupleDesc desc) HeapTuple typeTup; Form_pg_type typeStruct; - datum = ObjectIdGetDatum(desc->attrs[i]->atttypid); - typeTup = SearchSysCache(TYPEOID, datum, 0, 0, 0); + typeTup = SearchSysCache(TYPEOID, + ObjectIdGetDatum(desc->attrs[i]->atttypid), + 0, 0, 0); if (!HeapTupleIsValid(typeTup)) - { - char *attname = NameStr(desc->attrs[i]->attname); - - elog(ERROR, "plpython: Cache lookup for attribute `%s' type `%u' failed", - attname, desc->attrs[i]->atttypid); - } - + elog(ERROR, "cache lookup failed for type %u", + desc->attrs[i]->atttypid); typeStruct = (Form_pg_type) GETSTRUCT(typeTup); PLy_output_datum_func2(&(arg->out.r.atts[i]), typeStruct); @@ -1333,7 +1324,7 @@ PLy_output_datum_func(PLyTypeInfo * arg, Form_pg_type typeStruct) enter(); if (arg->is_rel == 1) - elog(FATAL, "plpython: PLyTypeInfo struct is initialized for a Tuple"); + elog(ERROR, "PLyTypeInfo struct is initialized for a Tuple"); arg->is_rel = 0; PLy_output_datum_func2(&(arg->out.d), typeStruct); } @@ -1354,7 +1345,7 @@ PLy_input_datum_func(PLyTypeInfo * arg, Oid typeOid, Form_pg_type typeStruct) enter(); if (arg->is_rel == 1) - elog(FATAL, "plpython: PLyTypeInfo struct is initialized for Tuple"); + elog(ERROR, "PLyTypeInfo struct is initialized for Tuple"); arg->is_rel = 0; PLy_input_datum_func2(&(arg->in.d), typeOid, typeStruct); } @@ -1476,11 +1467,11 @@ PLyDict_FromTuple(PLyTypeInfo * info, HeapTuple tuple, TupleDesc desc) enter(); if (info->is_rel != 1) - elog(FATAL, "plpython: PLyTypeInfo structure describes a datum."); + elog(ERROR, "PLyTypeInfo structure describes a datum"); dict = PyDict_New(); if (dict == NULL) - PLy_elog(ERROR, "Unable to create tuple dictionary."); + PLy_elog(ERROR, "could not create tuple dictionary"); SAVE_EXC(); if (TRAP_EXC()) @@ -1915,7 +1906,8 @@ PLy_spi_prepare(PyObject * self, PyObject * args) Py_XDECREF(optr); if (!PyErr_Occurred()) PyErr_SetString(PLy_exc_spi_error, - "Unknown error in PLy_spi_prepare."); + "Unknown error in PLy_spi_prepare"); + /* XXX this oughta be replaced with errcontext mechanism */ PLy_elog(WARNING, "in function %s:", PLy_procedure_name(PLy_last_procedure)); RERAISE_EXC(); } @@ -2191,7 +2183,7 @@ PLy_spi_execute_query(char *query, int limit) RESTORE_EXC(); if ((!PLy_restart_in_progress) && (!PyErr_Occurred())) PyErr_SetString(PLy_exc_spi_error, - "Unknown error in PLy_spi_execute_query."); + "Unknown error in PLy_spi_execute_query"); PLy_elog(WARNING, "in function %s:", PLy_procedure_name(PLy_last_procedure)); RERAISE_EXC(); } @@ -2318,17 +2310,17 @@ PLy_init_all(void) enter(); if (init_active) - elog(FATAL, "plpython: Initialization of language module failed."); + elog(FATAL, "initialization of language module failed"); init_active = 1; Py_Initialize(); PLy_init_interp(); PLy_init_plpy(); if (PyErr_Occurred()) - PLy_elog(FATAL, "Untrapped error in initialization."); + PLy_elog(FATAL, "untrapped error in initialization"); PLy_procedure_cache = PyDict_New(); if (PLy_procedure_cache == NULL) - PLy_elog(ERROR, "Unable to create procedure cache."); + PLy_elog(ERROR, "could not create procedure cache"); PLy_first_call = 0; @@ -2344,14 +2336,14 @@ PLy_init_interp(void) mainmod = PyImport_AddModule("__main__"); if ((mainmod == NULL) || (PyErr_Occurred())) - PLy_elog(ERROR, "Unable to import '__main__' module."); + PLy_elog(ERROR, "could not import \"__main__\" module."); Py_INCREF(mainmod); PLy_interp_globals = PyModule_GetDict(mainmod); PLy_interp_safe_globals = PyDict_New(); PyDict_SetItemString(PLy_interp_globals, "GD", PLy_interp_safe_globals); Py_DECREF(mainmod); if ((PLy_interp_globals == NULL) || (PyErr_Occurred())) - PLy_elog(ERROR, "Unable to initialize globals."); + PLy_elog(ERROR, "could not initialize globals"); } void @@ -2389,7 +2381,7 @@ PLy_init_plpy(void) plpy_mod = PyImport_AddModule("plpy"); PyDict_SetItemString(main_dict, "plpy", plpy_mod); if (PyErr_Occurred()) - elog(ERROR, "Unable to init plpy."); + elog(ERROR, "could not init plpy"); } /* the python interface to the elog function @@ -2450,7 +2442,7 @@ PLy_output(volatile int level, PyObject * self, PyObject * args) enter(); if (args == NULL) - elog(WARNING, "plpython, args is NULL in %s", __FUNCTION__); + elog(WARNING, "args is NULL"); so = PyObject_Str(args); if ((so == NULL) || ((sv = PyString_AsString(so)) == NULL)) @@ -2492,7 +2484,7 @@ PLy_output(volatile int level, PyObject * self, PyObject * args) * postgresql log, no? whatever, this shouldn't happen so die * hideously. */ - elog(FATAL, "plpython: Aiieee, elog threw an unknown exception!"); + elog(FATAL, "elog threw an unknown exception"); RERAISE_EXC(); } @@ -2576,18 +2568,18 @@ PLy_elog(int elevel, const char *fmt,...) */ PLy_restart_in_progress += 1; PLy_free(emsg); - PLy_free(xmsg); + if (xmsg) + PLy_free(xmsg); RERAISE_EXC(); } - if (xmsg) - { - elog(elevel, "plpython: %s\n%s", emsg, xmsg); - PLy_free(xmsg); - } - else - elog(elevel, "plpython: %s", emsg); + ereport(elevel, + (errmsg("plpython: %s", emsg), + (xmsg) ? errdetail("%s", xmsg) : 0)); + PLy_free(emsg); + if (xmsg) + PLy_free(xmsg); leave(); @@ -2706,7 +2698,9 @@ PLy_malloc(size_t bytes) void *ptr = malloc(bytes); if (ptr == NULL) - elog(FATAL, "plpython: Memory exhausted."); + ereport(FATAL, + (errcode(ERRCODE_OUT_OF_MEMORY), + errmsg("out of memory"))); return ptr; } @@ -2716,7 +2710,9 @@ PLy_realloc(void *optr, size_t bytes) void *nptr = realloc(optr, bytes); if (nptr == NULL) - elog(FATAL, "plpython: Memory exhausted."); + ereport(FATAL, + (errcode(ERRCODE_OUT_OF_MEMORY), + errmsg("out of memory"))); return nptr; } diff --git a/src/pl/plpython/plpython.h b/src/pl/plpython/plpython.h index 5b5300c83d..d6060ee373 100644 --- a/src/pl/plpython/plpython.h +++ b/src/pl/plpython/plpython.h @@ -1,4 +1,4 @@ -/* $Header: /cvsroot/pgsql/src/pl/plpython/Attic/plpython.h,v 1.7 2003/05/27 17:49:47 momjian Exp $ */ +/* $Header: /cvsroot/pgsql/src/pl/plpython/Attic/plpython.h,v 1.8 2003/07/25 23:37:30 tgl Exp $ */ #ifndef PLPYTHON_H #define PLPYTHON_H @@ -43,8 +43,8 @@ #if DEBUG_LEVEL #define CALL_LEVEL_INC() do { PLy_call_level += 1; \ - elog(DEBUG4, "Level: %d", PLy_call_level); } while (0) -#define CALL_LEVEL_DEC() do { elog(DEBUG4, "Level: %d", PLy_call_level); \ + elog(DEBUG4, "level: %d", PLy_call_level); } while (0) +#define CALL_LEVEL_DEC() do { elog(DEBUG4, "level: %d", PLy_call_level); \ PLy_call_level -= 1; } while (0) #else #define CALL_LEVEL_INC() do { PLy_call_level += 1; } while (0) diff --git a/src/pl/tcl/pltcl.c b/src/pl/tcl/pltcl.c index 35414d7889..2f14245ee1 100644 --- a/src/pl/tcl/pltcl.c +++ b/src/pl/tcl/pltcl.c @@ -31,7 +31,7 @@ * ENHANCEMENTS, OR MODIFICATIONS. * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/pl/tcl/pltcl.c,v 1.71 2003/05/27 17:49:47 momjian Exp $ + * $Header: /cvsroot/pgsql/src/pl/tcl/pltcl.c,v 1.72 2003/07/25 23:37:31 tgl Exp $ * **********************************************************************/ @@ -215,28 +215,19 @@ pltcl_init_all(void) * stdout and stderr on DeleteInterp ************************************************************/ if ((pltcl_hold_interp = Tcl_CreateInterp()) == NULL) - { - elog(ERROR, "pltcl: internal error - cannot create 'hold' " - "interpreter"); - } + elog(ERROR, "could not create \"hold\" interpreter"); /************************************************************ * Create the two interpreters ************************************************************/ if ((pltcl_norm_interp = Tcl_CreateSlave(pltcl_hold_interp, "norm", 0)) == NULL) - { - elog(ERROR, - "pltcl: internal error - cannot create 'normal' interpreter"); - } + elog(ERROR, "could not create \"normal\" interpreter"); pltcl_init_interp(pltcl_norm_interp); if ((pltcl_safe_interp = Tcl_CreateSlave(pltcl_hold_interp, "safe", 1)) == NULL) - { - elog(ERROR, - "pltcl: internal error - cannot create 'safe' interpreter"); - } + elog(ERROR, "could not create \"safe\" interpreter"); pltcl_init_interp(pltcl_safe_interp); /************************************************************ @@ -285,10 +276,10 @@ pltcl_init_interp(Tcl_Interp *interp) * Try to load the unknown procedure from pltcl_modules ************************************************************/ if (SPI_connect() != SPI_OK_CONNECT) - elog(ERROR, "pltcl_init_interp(): SPI_connect failed"); + elog(ERROR, "SPI_connect failed"); pltcl_init_load_unknown(interp); if (SPI_finish() != SPI_OK_FINISH) - elog(ERROR, "pltcl_init_interp(): SPI_finish failed"); + elog(ERROR, "SPI_finish failed"); } @@ -313,7 +304,7 @@ pltcl_init_load_unknown(Tcl_Interp *interp) "where relname = 'pltcl_modules'", 1); SPI_freetuptable(SPI_tuptable); if (spi_rc != SPI_OK_SELECT) - elog(ERROR, "pltcl_init_load_unknown(): select from pg_class failed"); + elog(ERROR, "select from pg_class failed"); if (SPI_processed == 0) return; @@ -327,10 +318,7 @@ pltcl_init_load_unknown(Tcl_Interp *interp) "where modname = 'unknown' " "order by modseq", 0); if (spi_rc != SPI_OK_SELECT) - { - elog(ERROR, "pltcl_init_load_unknown(): select from pltcl_modules " - "failed"); - } + elog(ERROR, "select from pltcl_modules failed"); /************************************************************ * If there's nothing, module unknown doesn't exist @@ -339,7 +327,7 @@ pltcl_init_load_unknown(Tcl_Interp *interp) { Tcl_DStringFree(&unknown_src); SPI_freetuptable(SPI_tuptable); - elog(WARNING, "pltcl: Module unknown not found in pltcl_modules"); + elog(WARNING, "module \"unknown\" not found in pltcl_modules"); return; } @@ -394,7 +382,7 @@ pltcl_call_handler(PG_FUNCTION_ARGS) * Connect to SPI manager ************************************************************/ if (SPI_connect() != SPI_OK_CONNECT) - elog(ERROR, "pltcl: cannot connect to SPI manager"); + elog(ERROR, "could not connect to SPI manager"); /************************************************************ * Keep track about the nesting of Tcl-SPI-Tcl-... calls ************************************************************/ @@ -550,9 +538,11 @@ pltcl_func_handler(PG_FUNCTION_ARGS) if (--pltcl_call_level == 0) pltcl_restart_in_progress = 0; UTF_BEGIN; - elog(ERROR, "pltcl: %s\n%s", interp->result, - UTF_U2E(Tcl_GetVar(interp, "errorInfo", - TCL_GLOBAL_ONLY))); + ereport(ERROR, + (errmsg("pltcl: %s", interp->result), + errdetail("%s", + UTF_U2E(Tcl_GetVar(interp, "errorInfo", + TCL_GLOBAL_ONLY))))); UTF_END; } if (--pltcl_call_level == 0) @@ -586,7 +576,7 @@ pltcl_func_handler(PG_FUNCTION_ARGS) * the result type in that case. ************************************************************/ if (SPI_finish() != SPI_OK_FINISH) - elog(ERROR, "pltcl: SPI_finish() failed"); + elog(ERROR, "SPI_finish() failed"); if (fcinfo->isnull) retval = (Datum) 0; @@ -785,9 +775,11 @@ pltcl_trigger_handler(PG_FUNCTION_ARGS) if (--pltcl_call_level == 0) pltcl_restart_in_progress = 0; UTF_BEGIN; - elog(ERROR, "pltcl: %s\n%s", interp->result, - UTF_U2E(Tcl_GetVar(interp, "errorInfo", - TCL_GLOBAL_ONLY))); + ereport(ERROR, + (errmsg("pltcl: %s", interp->result), + errdetail("%s", + UTF_U2E(Tcl_GetVar(interp, "errorInfo", + TCL_GLOBAL_ONLY))))); UTF_END; } if (--pltcl_call_level == 0) @@ -801,7 +793,7 @@ pltcl_trigger_handler(PG_FUNCTION_ARGS) break; default: - elog(ERROR, "pltcl: unsupported TCL return code %d", tcl_rc); + elog(ERROR, "unsupported TCL return code: %d", tcl_rc); } /************************************************************ @@ -809,7 +801,7 @@ pltcl_trigger_handler(PG_FUNCTION_ARGS) * the magic strings OK or SKIP or a list from array get ************************************************************/ if (SPI_finish() != SPI_OK_FINISH) - elog(ERROR, "pltcl: SPI_finish() failed"); + elog(ERROR, "SPI_finish() failed"); if (strcmp(interp->result, "OK") == 0) return rettup; @@ -822,15 +814,13 @@ pltcl_trigger_handler(PG_FUNCTION_ARGS) ************************************************************/ if (Tcl_SplitList(interp, interp->result, &ret_numvals, &ret_values) != TCL_OK) - { - elog(WARNING, "pltcl: cannot split return value from trigger"); - elog(ERROR, "pltcl: %s", interp->result); - } + elog(ERROR, "could not split return value from trigger: %s", + interp->result); if (ret_numvals % 2 != 0) { ckfree((char *) ret_values); - elog(ERROR, "pltcl: invalid return list from trigger - must have even # of elements"); + elog(ERROR, "invalid return list from trigger - must have even # of elements"); } modattrs = (int *) palloc(tupdesc->natts * sizeof(int)); @@ -881,9 +871,11 @@ pltcl_trigger_handler(PG_FUNCTION_ARGS) ************************************************************/ attnum = SPI_fnumber(tupdesc, ret_values[i++]); if (attnum == SPI_ERROR_NOATTRIBUTE) - elog(ERROR, "pltcl: invalid attribute '%s'", ret_values[--i]); + elog(ERROR, "invalid attribute \"%s\"", + ret_values[--i]); if (attnum <= 0) - elog(ERROR, "pltcl: cannot set system attribute '%s'", ret_values[--i]); + elog(ERROR, "cannot set system attribute \"%s\"", + ret_values[--i]); /************************************************************ * Lookup the attribute type in the syscache @@ -893,11 +885,8 @@ pltcl_trigger_handler(PG_FUNCTION_ARGS) ObjectIdGetDatum(tupdesc->attrs[attnum - 1]->atttypid), 0, 0, 0); if (!HeapTupleIsValid(typeTup)) - { - elog(ERROR, "pltcl: Cache lookup for attribute '%s' type %u failed", - ret_values[--i], + elog(ERROR, "cache lookup failed for type %u", tupdesc->attrs[attnum - 1]->atttypid); - } typinput = ((Form_pg_type) GETSTRUCT(typeTup))->typinput; typelem = ((Form_pg_type) GETSTRUCT(typeTup))->typelem; ReleaseSysCache(typeTup); @@ -924,7 +913,7 @@ pltcl_trigger_handler(PG_FUNCTION_ARGS) pfree(modnulls); if (rettup == NULL) - elog(ERROR, "pltcl: SPI_modifytuple() failed - RC = %d\n", SPI_result); + elog(ERROR, "SPI_modifytuple() failed - RC = %d", SPI_result); ckfree((char *) ret_values); memcpy(&Warn_restart, &save_restart, sizeof(Warn_restart)); @@ -954,7 +943,7 @@ compile_pltcl_function(Oid fn_oid, bool is_trigger) ObjectIdGetDatum(fn_oid), 0, 0, 0); if (!HeapTupleIsValid(procTup)) - elog(ERROR, "pltcl: cache lookup for proc %u failed", fn_oid); + elog(ERROR, "cache lookup failed for function %u", fn_oid); procStruct = (Form_pg_proc) GETSTRUCT(procTup); /************************************************************ @@ -1018,7 +1007,9 @@ compile_pltcl_function(Oid fn_oid, bool is_trigger) ************************************************************/ prodesc = (pltcl_proc_desc *) malloc(sizeof(pltcl_proc_desc)); if (prodesc == NULL) - elog(ERROR, "pltcl: out of memory"); + ereport(ERROR, + (errcode(ERRCODE_OUT_OF_MEMORY), + errmsg("out of memory"))); MemSet(prodesc, 0, sizeof(pltcl_proc_desc)); prodesc->proname = strdup(internal_proname); prodesc->fn_xmin = HeapTupleHeaderGetXmin(procTup->t_data); @@ -1034,7 +1025,7 @@ compile_pltcl_function(Oid fn_oid, bool is_trigger) { free(prodesc->proname); free(prodesc); - elog(ERROR, "pltcl: cache lookup for language %u failed", + elog(ERROR, "cache lookup failed for language %u", procStruct->prolang); } langStruct = (Form_pg_language) GETSTRUCT(langTup); @@ -1059,7 +1050,7 @@ compile_pltcl_function(Oid fn_oid, bool is_trigger) { free(prodesc->proname); free(prodesc); - elog(ERROR, "pltcl: cache lookup for return type %u failed", + elog(ERROR, "cache lookup failed for type %u", procStruct->prorettype); } typeStruct = (Form_pg_type) GETSTRUCT(typeTup); @@ -1073,16 +1064,18 @@ compile_pltcl_function(Oid fn_oid, bool is_trigger) { free(prodesc->proname); free(prodesc); - elog(ERROR, "pltcl functions cannot return type %s" - "\n\texcept when used as triggers", - format_type_be(procStruct->prorettype)); + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("trigger functions may only be called as triggers"))); } else { free(prodesc->proname); free(prodesc); - elog(ERROR, "pltcl functions cannot return type %s", - format_type_be(procStruct->prorettype)); + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("pltcl functions cannot return type %s", + format_type_be(procStruct->prorettype)))); } } @@ -1090,7 +1083,9 @@ compile_pltcl_function(Oid fn_oid, bool is_trigger) { free(prodesc->proname); free(prodesc); - elog(ERROR, "pltcl: return types of tuples not supported yet"); + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("pltcl functions cannot return tuples yet"))); } perm_fmgr_info(typeStruct->typinput, &(prodesc->result_in_func)); @@ -1116,7 +1111,7 @@ compile_pltcl_function(Oid fn_oid, bool is_trigger) { free(prodesc->proname); free(prodesc); - elog(ERROR, "pltcl: cache lookup for argument type %u failed", + elog(ERROR, "cache lookup failed for type %u", procStruct->proargtypes[i]); } typeStruct = (Form_pg_type) GETSTRUCT(typeTup); @@ -1126,8 +1121,10 @@ compile_pltcl_function(Oid fn_oid, bool is_trigger) { free(prodesc->proname); free(prodesc); - elog(ERROR, "pltcl functions cannot take type %s", - format_type_be(procStruct->proargtypes[i])); + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("pltcl functions cannot take type %s", + format_type_be(procStruct->proargtypes[i])))); } if (typeStruct->typrelid != InvalidOid) @@ -1230,7 +1227,7 @@ compile_pltcl_function(Oid fn_oid, bool is_trigger) { free(prodesc->proname); free(prodesc); - elog(ERROR, "pltcl: cannot create internal procedure %s - %s", + elog(ERROR, "could not create internal procedure \"%s\": %s", internal_proname, interp->result); } @@ -1802,45 +1799,8 @@ pltcl_SPI_prepare(ClientData cdata, Tcl_Interp *interp, if (plan == NULL) { - char buf[128]; - char *reason; - memcpy(&Warn_restart, &save_restart, sizeof(Warn_restart)); - - switch (SPI_result) - { - case SPI_ERROR_ARGUMENT: - reason = "SPI_ERROR_ARGUMENT"; - break; - - case SPI_ERROR_UNCONNECTED: - reason = "SPI_ERROR_UNCONNECTED"; - break; - - case SPI_ERROR_COPY: - reason = "SPI_ERROR_COPY"; - break; - - case SPI_ERROR_CURSOR: - reason = "SPI_ERROR_CURSOR"; - break; - - case SPI_ERROR_TRANSACTION: - reason = "SPI_ERROR_TRANSACTION"; - break; - - case SPI_ERROR_OPUNKNOWN: - reason = "SPI_ERROR_OPUNKNOWN"; - break; - - default: - snprintf(buf, sizeof(buf), "unknown RC %d", SPI_result); - reason = buf; - break; - - } - - elog(ERROR, "pltcl: SPI_prepare() failed - %s", reason); + elog(ERROR, "SPI_prepare() failed"); } /************************************************************ @@ -1850,29 +1810,8 @@ pltcl_SPI_prepare(ClientData cdata, Tcl_Interp *interp, qdesc->plan = SPI_saveplan(plan); if (qdesc->plan == NULL) { - char buf[128]; - char *reason; - memcpy(&Warn_restart, &save_restart, sizeof(Warn_restart)); - - switch (SPI_result) - { - case SPI_ERROR_ARGUMENT: - reason = "SPI_ERROR_ARGUMENT"; - break; - - case SPI_ERROR_UNCONNECTED: - reason = "SPI_ERROR_UNCONNECTED"; - break; - - default: - snprintf(buf, sizeof(buf), "unknown RC %d", SPI_result); - reason = buf; - break; - - } - - elog(ERROR, "pltcl: SPI_saveplan() failed - %s", reason); + elog(ERROR, "SPI_saveplan() failed"); } /* Release the procCxt copy to avoid within-function memory leak */ SPI_freeplan(plan); @@ -2359,10 +2298,8 @@ pltcl_set_tuple_values(Tcl_Interp *interp, CONST84 char *arrayname, ObjectIdGetDatum(tupdesc->attrs[i]->atttypid), 0, 0, 0); if (!HeapTupleIsValid(typeTup)) - { - elog(ERROR, "pltcl: Cache lookup for attribute '%s' type %u failed", - attname, tupdesc->attrs[i]->atttypid); - } + elog(ERROR, "cache lookup failed for type %u", + tupdesc->attrs[i]->atttypid); typoutput = ((Form_pg_type) GETSTRUCT(typeTup))->typoutput; typelem = ((Form_pg_type) GETSTRUCT(typeTup))->typelem; @@ -2431,10 +2368,8 @@ pltcl_build_tuple_argument(HeapTuple tuple, TupleDesc tupdesc, ObjectIdGetDatum(tupdesc->attrs[i]->atttypid), 0, 0, 0); if (!HeapTupleIsValid(typeTup)) - { - elog(ERROR, "pltcl: Cache lookup for attribute '%s' type %u failed", - attname, tupdesc->attrs[i]->atttypid); - } + elog(ERROR, "cache lookup failed for type %u", + tupdesc->attrs[i]->atttypid); typoutput = ((Form_pg_type) GETSTRUCT(typeTup))->typoutput; typelem = ((Form_pg_type) GETSTRUCT(typeTup))->typelem;