diff options
Diffstat (limited to 'src/pl')
-rw-r--r-- | src/pl/plperl/plperl.c | 70 | ||||
-rw-r--r-- | src/pl/plpython/plpy_elog.c | 2 | ||||
-rw-r--r-- | src/pl/plpython/plpy_exec.c | 12 | ||||
-rw-r--r-- | src/pl/tcl/pltcl.c | 51 |
4 files changed, 91 insertions, 44 deletions
diff --git a/src/pl/plperl/plperl.c b/src/pl/plperl/plperl.c index 78baaac05db..ae0ba19814f 100644 --- a/src/pl/plperl/plperl.c +++ b/src/pl/plperl/plperl.c @@ -640,8 +640,9 @@ select_perl_context(bool trusted) else plperl_untrusted_init(); #else - elog(ERROR, - "cannot allocate multiple Perl interpreters on this platform"); + errmsg(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("cannot allocate multiple Perl interpreters on this platform"))); #endif } @@ -660,7 +661,8 @@ select_perl_context(bool trusted) eval_pv("PostgreSQL::InServer::SPI::bootstrap()", FALSE); if (SvTRUE(ERRSV)) ereport(ERROR, - (errmsg("%s", strip_trailing_ws(sv2cstr(ERRSV))), + (errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION), + errmsg("%s", strip_trailing_ws(sv2cstr(ERRSV))), errcontext("while executing PostgreSQL::InServer::SPI::bootstrap"))); /* Fully initialized, so mark the hashtable entry valid */ @@ -834,12 +836,14 @@ plperl_init_interp(void) if (perl_parse(plperl, plperl_init_shared_libs, nargs, embedding, NULL) != 0) ereport(ERROR, - (errmsg("%s", strip_trailing_ws(sv2cstr(ERRSV))), + (errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION), + errmsg("%s", strip_trailing_ws(sv2cstr(ERRSV))), errcontext("while parsing Perl initialization"))); if (perl_run(plperl) != 0) ereport(ERROR, - (errmsg("%s", strip_trailing_ws(sv2cstr(ERRSV))), + (errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION), + errmsg("%s", strip_trailing_ws(sv2cstr(ERRSV))), errcontext("while running Perl initialization"))); #ifdef PLPERL_RESTORE_LOCALE @@ -952,7 +956,8 @@ plperl_trusted_init(void) eval_pv(PLC_TRUSTED, FALSE); if (SvTRUE(ERRSV)) ereport(ERROR, - (errmsg("%s", strip_trailing_ws(sv2cstr(ERRSV))), + (errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION), + errmsg("%s", strip_trailing_ws(sv2cstr(ERRSV))), errcontext("while executing PLC_TRUSTED"))); /* @@ -963,7 +968,8 @@ plperl_trusted_init(void) eval_pv("my $a=chr(0x100); return $a =~ /\\xa9/i", FALSE); if (SvTRUE(ERRSV)) ereport(ERROR, - (errmsg("%s", strip_trailing_ws(sv2cstr(ERRSV))), + (errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION), + errmsg("%s", strip_trailing_ws(sv2cstr(ERRSV))), errcontext("while executing utf8fix"))); /* @@ -1002,11 +1008,12 @@ plperl_trusted_init(void) if (plperl_on_plperl_init && *plperl_on_plperl_init) { eval_pv(plperl_on_plperl_init, FALSE); + /* XXX need to find a way to determine a better errcode here */ if (SvTRUE(ERRSV)) ereport(ERROR, - (errmsg("%s", strip_trailing_ws(sv2cstr(ERRSV))), + (errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION), + errmsg("%s", strip_trailing_ws(sv2cstr(ERRSV))), errcontext("while executing plperl.on_plperl_init"))); - } } @@ -1025,7 +1032,8 @@ plperl_untrusted_init(void) eval_pv(plperl_on_plperlu_init, FALSE); if (SvTRUE(ERRSV)) ereport(ERROR, - (errmsg("%s", strip_trailing_ws(sv2cstr(ERRSV))), + (errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION), + errmsg("%s", strip_trailing_ws(sv2cstr(ERRSV))), errcontext("while executing plperl.on_plperlu_init"))); } } @@ -1382,7 +1390,9 @@ plperl_sv_to_literal(SV *sv, char *fqtypename) isnull; if (!OidIsValid(typid)) - elog(ERROR, "lookup failed for type %s", fqtypename); + ereport(ERROR, + (errcode(ERRCODE_UNDEFINED_OBJECT), + errmsg("lookup failed for type %s", fqtypename))); datum = plperl_sv_to_datum(sv, typid, -1, @@ -2059,7 +2069,8 @@ plperl_create_sub(plperl_proc_desc *prodesc, char *s, Oid fn_oid) if (!subref) ereport(ERROR, - (errmsg("didn't get a CODE reference from compiling function \"%s\"", + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("didn't get a CODE reference from compiling function \"%s\"", prodesc->proname))); prodesc->reference = subref; @@ -2147,7 +2158,9 @@ plperl_call_perl_func(plperl_proc_desc *desc, FunctionCallInfo fcinfo) PUTBACK; FREETMPS; LEAVE; - elog(ERROR, "didn't get a return item from function"); + ereport(ERROR, + (errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION), + errmsg("didn't get a return item from function"))); } if (SvTRUE(ERRSV)) @@ -2156,9 +2169,10 @@ plperl_call_perl_func(plperl_proc_desc *desc, FunctionCallInfo fcinfo) PUTBACK; FREETMPS; LEAVE; - /* XXX need to find a way to assign an errcode here */ + /* XXX need to find a way to determine a better errcode here */ ereport(ERROR, - (errmsg("%s", strip_trailing_ws(sv2cstr(ERRSV))))); + (errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION), + errmsg("%s", strip_trailing_ws(sv2cstr(ERRSV))))); } retval = newSVsv(POPs); @@ -2187,7 +2201,9 @@ plperl_call_perl_trigger_func(plperl_proc_desc *desc, FunctionCallInfo fcinfo, TDsv = get_sv("main::_TD", 0); if (!TDsv) - elog(ERROR, "couldn't fetch $_TD"); + ereport(ERROR, + (errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION), + errmsg("couldn't fetch $_TD"))); save_item(TDsv); /* local $_TD */ sv_setsv(TDsv, td); @@ -2209,7 +2225,9 @@ plperl_call_perl_trigger_func(plperl_proc_desc *desc, FunctionCallInfo fcinfo, PUTBACK; FREETMPS; LEAVE; - elog(ERROR, "didn't get a return item from trigger function"); + ereport(ERROR, + (errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION), + errmsg("didn't get a return item from trigger function"))); } if (SvTRUE(ERRSV)) @@ -2218,9 +2236,10 @@ plperl_call_perl_trigger_func(plperl_proc_desc *desc, FunctionCallInfo fcinfo, PUTBACK; FREETMPS; LEAVE; - /* XXX need to find a way to assign an errcode here */ + /* XXX need to find a way to determine a better errcode here */ ereport(ERROR, - (errmsg("%s", strip_trailing_ws(sv2cstr(ERRSV))))); + (errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION), + errmsg("%s", strip_trailing_ws(sv2cstr(ERRSV))))); } retval = newSVsv(POPs); @@ -2248,7 +2267,9 @@ plperl_call_perl_event_trigger_func(plperl_proc_desc *desc, TDsv = get_sv("main::_TD", 0); if (!TDsv) - elog(ERROR, "couldn't fetch $_TD"); + ereport(ERROR, + (errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION), + errmsg("couldn't fetch $_TD"))); save_item(TDsv); /* local $_TD */ sv_setsv(TDsv, td); @@ -2266,7 +2287,9 @@ plperl_call_perl_event_trigger_func(plperl_proc_desc *desc, PUTBACK; FREETMPS; LEAVE; - elog(ERROR, "didn't get a return item from trigger function"); + ereport(ERROR, + (errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION), + errmsg("didn't get a return item from trigger function"))); } if (SvTRUE(ERRSV)) @@ -2275,9 +2298,10 @@ plperl_call_perl_event_trigger_func(plperl_proc_desc *desc, PUTBACK; FREETMPS; LEAVE; - /* XXX need to find a way to assign an errcode here */ + /* XXX need to find a way to determine a better errcode here */ ereport(ERROR, - (errmsg("%s", strip_trailing_ws(sv2cstr(ERRSV))))); + (errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION), + errmsg("%s", strip_trailing_ws(sv2cstr(ERRSV))))); } retval = newSVsv(POPs); diff --git a/src/pl/plpython/plpy_elog.c b/src/pl/plpython/plpy_elog.c index 461d68c5461..15406d60b90 100644 --- a/src/pl/plpython/plpy_elog.c +++ b/src/pl/plpython/plpy_elog.c @@ -97,7 +97,7 @@ PLy_elog(int elevel, const char *fmt,...) PG_TRY(); { ereport(elevel, - (errcode(sqlerrcode ? sqlerrcode : ERRCODE_INTERNAL_ERROR), + (errcode(sqlerrcode ? sqlerrcode : ERRCODE_EXTERNAL_ROUTINE_EXCEPTION), errmsg_internal("%s", primary ? primary : "no exception data"), (detail) ? errdetail_internal("%s", detail) : 0, (tb_depth > 0 && tbmsg) ? errcontext("%s", tbmsg) : 0, diff --git a/src/pl/plpython/plpy_exec.c b/src/pl/plpython/plpy_exec.c index 8c525c932a7..3ccebe403e4 100644 --- a/src/pl/plpython/plpy_exec.c +++ b/src/pl/plpython/plpy_exec.c @@ -662,11 +662,13 @@ PLy_modify_tuple(PLyProcedure *proc, PyObject *pltd, TriggerData *tdata, { if ((plntup = PyDict_GetItemString(pltd, "new")) == NULL) ereport(ERROR, - (errmsg("TD[\"new\"] deleted, cannot modify row"))); + (errcode(ERRCODE_UNDEFINED_OBJECT), + errmsg("TD[\"new\"] deleted, cannot modify row"))); Py_INCREF(plntup); if (!PyDict_Check(plntup)) ereport(ERROR, - (errmsg("TD[\"new\"] is not a dictionary"))); + (errcode(ERRCODE_DATATYPE_MISMATCH), + errmsg("TD[\"new\"] is not a dictionary"))); plkeys = PyDict_Keys(plntup); natts = PyList_Size(plkeys); @@ -690,13 +692,15 @@ PLy_modify_tuple(PLyProcedure *proc, PyObject *pltd, TriggerData *tdata, else { ereport(ERROR, - (errmsg("TD[\"new\"] dictionary key at ordinal position %d is not a string", i))); + (errcode(ERRCODE_DATATYPE_MISMATCH), + errmsg("TD[\"new\"] dictionary key at ordinal position %d is not a string", i))); plattstr = NULL; /* keep compiler quiet */ } attn = SPI_fnumber(tupdesc, plattstr); if (attn == SPI_ERROR_NOATTRIBUTE) ereport(ERROR, - (errmsg("key \"%s\" found in TD[\"new\"] does not exist as a column in the triggering row", + (errcode(ERRCODE_UNDEFINED_COLUMN), + errmsg("key \"%s\" found in TD[\"new\"] does not exist as a column in the triggering row", plattstr))); atti = attn - 1; diff --git a/src/pl/tcl/pltcl.c b/src/pl/tcl/pltcl.c index 48a3206da1c..edfda5915b2 100644 --- a/src/pl/tcl/pltcl.c +++ b/src/pl/tcl/pltcl.c @@ -551,7 +551,8 @@ pltcl_init_load_unknown(Tcl_Interp *interp) if (SPI_processed == 0) { SPI_freetuptable(SPI_tuptable); - elog(WARNING, "module \"unknown\" not found in pltcl_modules"); + ereport(WARNING, + (errmsg("module \"unknown\" not found in pltcl_modules"))); relation_close(pmrel, AccessShareLock); return; } @@ -585,8 +586,10 @@ pltcl_init_load_unknown(Tcl_Interp *interp) if (tcl_rc != TCL_OK) { UTF_BEGIN; - elog(ERROR, "could not load module \"unknown\": %s", - UTF_U2E(Tcl_GetStringResult(interp))); + ereport(ERROR, + (errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION), + errmsg("could not load module \"unknown\": %s", + UTF_U2E(Tcl_GetStringResult(interp))))); UTF_END; } @@ -1039,8 +1042,10 @@ pltcl_trigger_handler(PG_FUNCTION_ARGS, bool pltrusted) &ret_numvals, &ret_values) != TCL_OK) { UTF_BEGIN; - elog(ERROR, "could not split return value from trigger: %s", - UTF_U2E(Tcl_GetStringResult(interp))); + ereport(ERROR, + (errcode(ERRCODE_E_R_I_E_TRIGGER_PROTOCOL_VIOLATED), + errmsg("could not split return value from trigger: %s", + UTF_U2E(Tcl_GetStringResult(interp))))); UTF_END; } @@ -1048,7 +1053,9 @@ pltcl_trigger_handler(PG_FUNCTION_ARGS, bool pltrusted) PG_TRY(); { if (ret_numvals % 2 != 0) - elog(ERROR, "invalid return list from trigger - must have even # of elements"); + ereport(ERROR, + (errcode(ERRCODE_E_R_I_E_TRIGGER_PROTOCOL_VIOLATED), + errmsg("invalid return list from trigger - must have even # of elements"))); modattrs = (int *) palloc(tupdesc->natts * sizeof(int)); modvalues = (Datum *) palloc(tupdesc->natts * sizeof(Datum)); @@ -1082,9 +1089,15 @@ pltcl_trigger_handler(PG_FUNCTION_ARGS, bool pltrusted) ************************************************************/ attnum = SPI_fnumber(tupdesc, ret_name); if (attnum == SPI_ERROR_NOATTRIBUTE) - elog(ERROR, "invalid attribute \"%s\"", ret_name); + ereport(ERROR, + (errcode(ERRCODE_UNDEFINED_COLUMN), + errmsg("unrecognized attribute \"%s\"", + ret_name))); if (attnum <= 0) - elog(ERROR, "cannot set system attribute \"%s\"", ret_name); + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("cannot set system attribute \"%s\"", + ret_name))); /************************************************************ * Ignore dropped columns @@ -1205,7 +1218,8 @@ throw_tcl_error(Tcl_Interp *interp, const char *proname) econtext = UTF_U2E((char *) Tcl_GetVar(interp, "errorInfo", TCL_GLOBAL_ONLY)); ereport(ERROR, - (errmsg("%s", emsg), + (errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION), + errmsg("%s", emsg), errcontext("%s\nin PL/Tcl function \"%s\"", econtext, proname))); UTF_END; @@ -1545,8 +1559,11 @@ compile_pltcl_function(Oid fn_oid, Oid tgreloid, free(prodesc->internal_proname); free(prodesc); UTF_BEGIN; - elog(ERROR, "could not create internal procedure \"%s\": %s", - internal_proname, UTF_U2E(Tcl_GetStringResult(interp))); + ereport(ERROR, + (errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION), + errmsg("could not create internal procedure \"%s\": %s", + internal_proname, + UTF_U2E(Tcl_GetStringResult(interp))))); UTF_END; } @@ -1614,10 +1631,10 @@ pltcl_elog(ClientData cdata, Tcl_Interp *interp, } /* - * For non-error messages, just pass 'em to elog(). We do not expect that - * this will fail, but just on the off chance it does, report the error - * back to Tcl. Note we are assuming that elog() can't have any internal - * failures that are so bad as to require a transaction abort. + * For non-error messages, just pass 'em to ereport(). We do not expect + * that this will fail, but just on the off chance it does, report the + * error back to Tcl. Note we are assuming that ereport() can't have any + * internal failures that are so bad as to require a transaction abort. * * This path is also used for FATAL errors, which aren't going to come * back to us at all. @@ -1626,7 +1643,9 @@ pltcl_elog(ClientData cdata, Tcl_Interp *interp, PG_TRY(); { UTF_BEGIN; - elog(level, "%s", UTF_U2E(argv[2])); + ereport(level, + (errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION), + errmsg("%s", UTF_U2E(argv[2])))); UTF_END; } PG_CATCH(); |