Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • hive/haf
  • dan/haf
2 results
Show changes
Commits on Source (2)
......@@ -63,11 +63,9 @@ namespace PsqlTools::PsqlUtils {
// If we're here, it most likely means we got an error from Postgres function we called without guarding PG_TRY/PG_CATCH.
// This most likely caused some C++ object to be `longjmp`ed over without proper destruction.
//
// We're in ErrorContext now, but CopyErrorData should not be called from that context, so we switch temporarily to context from before PG_TRY.
// Once we get the copy of error data, switch back to ErrorContext and report error.
MemoryContext errorContext = MemoryContextSwitchTo(oldcontext);
// We're in ErrorContext now, but CopyErrorData should not be called from that context, so we switch back to context from before PG_TRY.
MemoryContextSwitchTo(oldcontext);
ErrorData *edata = CopyErrorData();
MemoryContextSwitchTo(errorContext);
ereport( ERROR, ( errmsg( "An unexpected error occurred when executing C++ code: %s", edata->message ) ) );
}
PG_END_TRY();
......@@ -116,14 +114,14 @@ namespace PsqlTools::PsqlUtils {
}
PG_CATCH();
{
MemoryContext errorContext = MemoryContextSwitchTo(oldcontext);
MemoryContextSwitchTo(oldcontext);
ErrorData *edata = CopyErrorData();
error_message = edata->message;
MemoryContextSwitchTo(errorContext);
FlushErrorState();
}
PG_END_TRY();
if (ret.has_value()) return ret.value();
else throw PgError(error_message ? error_message : "");
else throw PgError(error_message ? error_message : "Unknown error while calling pg function");
}
template <size_t N>
......
......@@ -64,4 +64,9 @@ int geterrcode(void)
return last_errcode;
}
void FlushErrorState(void)
{
// do nothing
}
} // extern "C"