Skip to content

Conversation

@tpoliaw
Copy link
Contributor

@tpoliaw tpoliaw commented Jan 6, 2026

When building a catalog adapter, a subprocess is used to initialise the
database. If this process fails, the error (written to stderr) was lost
making it difficult to determine the cause.

By wrapping the stderr in a new exception and setting it to be the cause
of the raised CalledProcessException, Python displays it as

<subprocess stderr content>

The above exception was the direct cause of the following exception:

<the stacktrace of the command being run as before>

and the cause is more clearly visible.

@tpoliaw tpoliaw requested a review from danielballan January 6, 2026 18:36
When building a catalog adapter, a subprocess is used to initialise the
database, if this process fails, the error (written to stderr) was lost
making it difficult to determine the cause.

By wrapping the stderr in a new exception and setting it to be the cause
of the raised CalledProcessException, Python displays it as

    <subprocess stderr content>

    The above exception was the direct cause of the following exception:

    <the stacktrace of the command being run as before>

and the cause is more clearly visible.
@tpoliaw tpoliaw force-pushed the init_error_context branch from 9f75960 to e11a8cf Compare January 6, 2026 18:37
Copy link
Member

@danielballan danielballan left a comment

Choose a reason for hiding this comment

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

Nice technique! Hadn't seen this approach before.

@tpoliaw
Copy link
Contributor Author

tpoliaw commented Jan 6, 2026

Neither had I and there might be a good reason not to do it but it makes debugging much easier. The __cause__ field is at least documented which makes me less worried about relying on internals too much.

@danielballan danielballan merged commit 1fce3de into main Jan 6, 2026
10 of 12 checks passed
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.

3 participants