pg_duckdb icon indicating copy to clipboard operation
pg_duckdb copied to clipboard

Improve error handlers

Open Y-- opened this issue 7 months ago • 0 comments

Whenever a Postgres error is thrown and capture by our C++ code (or in DuckDB) we were re-throwing a generic duckdb::EXECUTOR for no specific reason.

Instead this PR throws a custom exception that captures the Postgres ErrorData object to be handled by the corresponding C++ exception handler, which will eventually convert it back to a Postgres exception.

The resulting errors are much nicer as a result and preserve more information. We could even add even more logging/tracing details such as which function was wrapped etc. (I was not sure where to put it exactly: context, detail, or NOTICE log, but trivial to improve).

The main drawback of this approach is that we have to serialize the ErrorData pointer to make sure that even if DuckDB capture the exception and re-throw with another type we do not loose the Postgres information, but there is no foul-proof way of making sure that the pointer will be valid in the C++ handler.

Y-- avatar May 06 '25 15:05 Y--