Move main error message text in plperl into errmsg from errdetail,

and move the context information into errcontext instead of errmsg.
This makes them better conform to our guidelines.

Also remove a few errcode declarations that were providing the default
value ERRCODE_INTERNAL_ERROR.
This commit is contained in:
Alvaro Herrera 2010-02-15 22:23:25 +00:00
parent 1acc06a1f4
commit 4a5ee2a419
2 changed files with 22 additions and 48 deletions

View File

@ -9,6 +9,6 @@ SHOW plperl.on_plperl_init;
(1 row) (1 row)
DO $$ warn 42 $$ language plperl; DO $$ warn 42 $$ language plperl;
ERROR: while executing plperl.on_plperl_init ERROR: 'eval "string"' trapped by operation mask at line 2.
DETAIL: 'eval "string"' trapped by operation mask at line 2. CONTEXT: While executing plperl.on_plperl_init.
CONTEXT: PL/Perl anonymous code block PL/Perl anonymous code block

View File

@ -1,7 +1,7 @@
/********************************************************************** /**********************************************************************
* plperl.c - perl as a procedural language for PostgreSQL * plperl.c - perl as a procedural language for PostgreSQL
* *
* $PostgreSQL: pgsql/src/pl/plperl/plperl.c,v 1.166 2010/02/14 18:42:18 rhaas Exp $ * $PostgreSQL: pgsql/src/pl/plperl/plperl.c,v 1.167 2010/02/15 22:23:25 alvherre Exp $
* *
**********************************************************************/ **********************************************************************/
@ -413,13 +413,9 @@ select_perl_context(bool trusted)
eval_pv("PostgreSQL::InServer::SPI::bootstrap()", FALSE); eval_pv("PostgreSQL::InServer::SPI::bootstrap()", FALSE);
if (SvTRUE(ERRSV)) if (SvTRUE(ERRSV))
{
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INTERNAL_ERROR), (errmsg("%s", strip_trailing_ws(SvPV_nolen(ERRSV))),
errmsg("%s", strip_trailing_ws(SvPV_nolen(ERRSV))), errdetail("While executing PostgreSQL::InServer::SPI::bootstrap.")));
errdetail("While executing PostgreSQL::InServer::SPI::bootstrap")));
}
} }
/* /*
@ -553,15 +549,13 @@ plperl_init_interp(void)
if (perl_parse(plperl, plperl_init_shared_libs, if (perl_parse(plperl, plperl_init_shared_libs,
nargs, embedding, NULL) != 0) nargs, embedding, NULL) != 0)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INTERNAL_ERROR), (errmsg("%s", strip_trailing_ws(SvPV_nolen(ERRSV))),
errmsg("while parsing perl initialization"), errcontext("While parsing perl initialization.")));
errdetail("%s", strip_trailing_ws(SvPV_nolen(ERRSV))) ));
if (perl_run(plperl) != 0) if (perl_run(plperl) != 0)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INTERNAL_ERROR), (errmsg("%s", strip_trailing_ws(SvPV_nolen(ERRSV))),
errmsg("while running perl initialization"), errcontext("While running perl initialization.")));
errdetail("%s", strip_trailing_ws(SvPV_nolen(ERRSV))) ));
#ifdef WIN32 #ifdef WIN32
@ -691,24 +685,17 @@ plperl_trusted_init(void)
/* not safe, so disallow all trusted funcs */ /* not safe, so disallow all trusted funcs */
eval_pv(PLC_SAFE_BAD, FALSE); eval_pv(PLC_SAFE_BAD, FALSE);
if (SvTRUE(ERRSV)) if (SvTRUE(ERRSV))
{
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INTERNAL_ERROR), (errmsg("%s", strip_trailing_ws(SvPV_nolen(ERRSV))),
errmsg("while executing PLC_SAFE_BAD"), errcontext("While executing PLC_SAFE_BAD.")));
errdetail("%s", strip_trailing_ws(SvPV_nolen(ERRSV))) ));
}
} }
else else
{ {
eval_pv(PLC_SAFE_OK, FALSE); eval_pv(PLC_SAFE_OK, FALSE);
if (SvTRUE(ERRSV)) if (SvTRUE(ERRSV))
{
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INTERNAL_ERROR), (errmsg("%s", strip_trailing_ws(SvPV_nolen(ERRSV))),
errmsg("while executing PLC_SAFE_OK"), errcontext("While executing PLC_SAFE_OK.")));
errdetail("%s", strip_trailing_ws(SvPV_nolen(ERRSV))) ));
}
if (GetDatabaseEncoding() == PG_UTF8) if (GetDatabaseEncoding() == PG_UTF8)
{ {
@ -719,12 +706,9 @@ plperl_trusted_init(void)
*/ */
eval_pv("my $a=chr(0x100); return $a =~ /\\xa9/i", FALSE); eval_pv("my $a=chr(0x100); return $a =~ /\\xa9/i", FALSE);
if (SvTRUE(ERRSV)) if (SvTRUE(ERRSV))
{
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INTERNAL_ERROR), (errmsg("%s", strip_trailing_ws(SvPV_nolen(ERRSV))),
errmsg("while executing utf8fix"), errcontext("While executing utf8fix.")));
errdetail("%s", strip_trailing_ws(SvPV_nolen(ERRSV))) ));
}
} }
/* switch to the safe require opcode */ /* switch to the safe require opcode */
@ -742,12 +726,9 @@ plperl_trusted_init(void)
SPAGAIN; SPAGAIN;
if (SvTRUE(ERRSV)) if (SvTRUE(ERRSV))
{
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INTERNAL_ERROR), (errmsg("%s", strip_trailing_ws(SvPV_nolen(ERRSV))),
errmsg("while executing plperl.on_plperl_init"), errcontext("While executing plperl.on_plperl_init.")));
errdetail("%s", strip_trailing_ws(SvPV_nolen(ERRSV))) ));
}
} }
} }
@ -761,12 +742,9 @@ plperl_untrusted_init(void)
{ {
eval_pv(plperl_on_plperlu_init, FALSE); eval_pv(plperl_on_plperlu_init, FALSE);
if (SvTRUE(ERRSV)) if (SvTRUE(ERRSV))
{
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INTERNAL_ERROR), (errmsg("%s", strip_trailing_ws(SvPV_nolen(ERRSV))),
errmsg("while executing plperl.on_plperlu_init"), errcontext("While executing plperl.on_plperlu_init.")));
errdetail("%s", strip_trailing_ws(SvPV_nolen(ERRSV))) ));
}
} }
} }
@ -1299,18 +1277,14 @@ plperl_create_sub(plperl_proc_desc *prodesc, char *s, Oid fn_oid)
LEAVE; LEAVE;
if (SvTRUE(ERRSV)) if (SvTRUE(ERRSV))
{
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR), (errcode(ERRCODE_SYNTAX_ERROR),
errmsg("%s", strip_trailing_ws(SvPV_nolen(ERRSV))))); errmsg("%s", strip_trailing_ws(SvPV_nolen(ERRSV)))));
}
if (!subref) if (!subref)
{
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INTERNAL_ERROR), (errmsg("didn't get a GLOB from compiling %s via %s",
errmsg("didn't get a GLOB from compiling %s via %s", prodesc->proname, compile_sub))); prodesc->proname, compile_sub)));
}
prodesc->reference = newSVsv(subref); prodesc->reference = newSVsv(subref);