diff --git a/pg_rsupport.c b/pg_rsupport.c index 30a9621c..b229c727 100755 --- a/pg_rsupport.c +++ b/pg_rsupport.c @@ -33,6 +33,7 @@ #include "plr.h" extern MemoryContext plr_SPI_context; +extern char *last_R_error_msg; static SEXP rpgsql_get_results(int ntuples, SPITupleTable *tuptable); @@ -593,30 +594,20 @@ plr_SPI_lastoid(void) return result; } -#ifdef PG_VERSION_73_COMPAT -/************************************************************************* - * working with postgres 7.3 compatible sources - *************************************************************************/ void throw_r_error(const char **msg) { - throw_pg_notice(msg); + if (msg && *msg) + last_R_error_msg = pstrdup(*msg); + else + last_R_error_msg = pstrdup("caught error calling R function"); } -#else +#ifndef PG_VERSION_73_COMPAT /************************************************************************* * working with postgres 7.4 compatible sources *************************************************************************/ -void -throw_r_error(const char **msg) -{ - if (msg && *msg) - elog(ERROR, "%s", *msg); - else - elog(ERROR, "%s", ""); -} - /* * error context callback to let us supply a call-stack traceback */ diff --git a/plr.c b/plr.c index 7c683ba4..3dfcb83e 100755 --- a/plr.c +++ b/plr.c @@ -37,6 +37,7 @@ */ MemoryContext plr_SPI_context; HTAB *plr_HashTable = (HTAB *) NULL; +char *last_R_error_msg = NULL; static bool plr_firstcall = true; static bool plr_interp_started = false; @@ -182,7 +183,10 @@ load_r_cmd(const char *cmd) PROTECT(cmdexpr = R_ParseVector(cmdSexp, -1, &status)); if (status != PARSE_OK) { UNPROTECT(2); - elog(ERROR, "plr: invalid R call: %s", cmd); + if (last_R_error_msg) + elog(ERROR, "%s", last_R_error_msg); + else + elog(ERROR, "R parse error: %s", cmd); } /* Loop is needed here as EXPSEXP may be of length > 1 */ @@ -190,7 +194,12 @@ load_r_cmd(const char *cmd) { ans = R_tryEval(VECTOR_ELT(cmdexpr, i), R_GlobalEnv, &status); if(status != 0) - elog(ERROR, "Caught an error calling R function"); + { + if (last_R_error_msg) + elog(ERROR, "%s", last_R_error_msg); + else + elog(ERROR, "%s", "caught error calling R function"); + } } UNPROTECT(2); @@ -836,7 +845,10 @@ plr_parse_func_body(const char *body) if (status != PARSE_OK) { UNPROTECT(2); - elog(ERROR, "plr: R parse error"); + if (last_R_error_msg) + elog(ERROR, "%s", last_R_error_msg); + else + elog(ERROR, "R parse error in function body"); } UNPROTECT(2); @@ -875,8 +887,12 @@ call_r_func(SEXP fun, SEXP rargs) UNPROTECT(1); if(errorOccurred) - elog(ERROR, "Caught an error calling R function"); - + { + if (last_R_error_msg) + elog(ERROR, "%s", last_R_error_msg); + else + elog(ERROR, "%s", "caught error calling R function"); + } return ans; }