Skip to content

Improve error handlers #760

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Improve error handlers #760

wants to merge 1 commit into from

Conversation

Y--
Copy link
Collaborator

@Y-- Y-- commented May 6, 2025

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-- Y-- requested a review from JelteF May 6, 2025 15:45
@Y-- Y-- force-pushed the yl/improve-func-guards branch from ac7be56 to e51c83d Compare May 6, 2025 15:50
Copy link
Collaborator

@JelteF JelteF left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really cool! I think we'll want something like this for sure, but I'm going to punt on reviewing this in detail until after the 1.0 release. It looks scary enough and touches important enough code that I'd like to have this bake for a while on the main branch.

throw duckdb::Exception(duckdb::ExceptionType::EXECUTOR, "Failed to extract Postgres error message");
pd_log(WARNING, "(PGGuard/%s) Exception in %s:%d: could not extract ErrorData.", func_name, file_name,
line);
throw Exception(); // This is a pretty bad situation - we failed to extract the error message.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove the error message from this exception?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just because it was a canned message and I wanted to throw a pgduckdb::Exception in both case, but we also could keep the original one.

@Y-- Y-- force-pushed the yl/improve-func-guards branch from e51c83d to 97f9b4f Compare May 6, 2025 16:05
@Y-- Y-- force-pushed the yl/improve-func-guards branch from 97f9b4f to e4bb734 Compare May 6, 2025 16:19
@Y-- Y-- added this to the 1.1.0 milestone May 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants