Skip to content

Conversation

Y--
Copy link
Collaborator

@Y-- Y-- commented May 5, 2025

Fixes #523

Reproduce elog(ERROR, ...) implementation to override the source function/file/line.

@Y-- Y-- requested a review from JelteF May 5, 2025 12:18
@Y-- Y-- force-pushed the yl/add-source-location branch from 22dd1df to f15f37c Compare May 5, 2025 12:21
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.

A few things:

  1. I think having the line number output in tests is going to cause a ton of diff noise when changing files.

  2. I think it's worth doing the more difficult thing to integrate into the normal postgres errors:

    The alternative would be to reproduce what elog(ERROR, ...) does and expose some of the elog.c internals.

    Afaict all that's needed is to inline the ereport/elog implementation, similarly to what we already do in include/pgduckdb/logger.hpp. And then change the call to errfinish to take the correct file, line number & function name.

  3. Changing InfokeCPPFunc like is a great start, but it's only half of the issue. I think we'd also want to to change PostgresFunctionGuard to store the original errdata in the exception, and propagate it upwards. Otherwise you'll always get the line info from the final wrapper location, not from the actual source. This could be done in a future PR though.

@Y--
Copy link
Collaborator Author

Y-- commented May 6, 2025

Afaict all that's needed is to inline the ereport/elog implementation, similarly to what we already do in include/pgduckdb/logger.hpp. And then change the call to errfinish to take the correct file, line number & function name.

I think I tried that but it wasn't working just quite. I'll revisit it.

@Y-- Y-- force-pushed the yl/add-source-location branch from 9696137 to 8bc83e1 Compare May 6, 2025 09:45
@Y--
Copy link
Collaborator Author

Y-- commented May 6, 2025

Afaict all that's needed is to inline the ereport/elog implementation, similarly to what we already do in include/pgduckdb/logger.hpp. And then change the call to errfinish to take the correct file, line number & function name.

I think I tried that but it wasn't working just quite. I'll revisit it.

Not sure what I missed yesterday but this wasn't actually that bad...

I'll also work on a PR for the PG wrapper.

@Y-- Y-- requested a review from JelteF May 6, 2025 09:47
@Y-- Y-- force-pushed the yl/add-source-location branch 2 times, most recently from 887977d to f4a93ec Compare May 6, 2025 09:50
@Y-- Y-- enabled auto-merge (squash) May 6, 2025 10:19
@Y-- Y-- force-pushed the yl/add-source-location branch 2 times, most recently from dbba048 to 46767f9 Compare May 6, 2025 13:26
@Y-- Y-- force-pushed the yl/add-source-location branch from 46767f9 to 8ee8c08 Compare May 6, 2025 14:14
@Y-- Y-- merged commit cbc28da into main May 6, 2025
6 checks passed
@Y-- Y-- deleted the yl/add-source-location branch May 6, 2025 15:41
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.

DuckDB errors converted to PG error always report the same source location
2 participants