duckdb icon indicating copy to clipboard operation
duckdb copied to clipboard

feat: hydrate python exceptions

Open Mause opened this issue 1 year ago • 4 comments

This is part of my efforts to improve the exceptions being thrown from the Python API - I still have to replace all the locations where std::runtime_error is being thrown directly.

I'm not sure if the path I've taken with the C++ changes is the right one, so feedback is definitely welcome

Mause avatar Aug 06 '22 05:08 Mause

@Mytherin it seems to me that this issue will affect all our APIs, is there a specific reason to turn query errors into strings? If not we should probably change this to pass on a DuckDBException of sorts, no?

Instead of reconstructing exceptions at the API level...

pdet avatar Aug 10 '22 09:08 pdet

@pdet it probably affects them all yes though I can't answer as to why we're turning them into strings in the first place

and we already have such an exception - duckdb::Exception

Mause avatar Aug 10 '22 09:08 Mause

Perhaps we should instead add the exception type to the query result, to avoid having to do string parsing to reconstruct the exception type?

Mytherin avatar Aug 10 '22 09:08 Mytherin

What is the rationale for just having the string (with the addition of an exception type) and not the duckdb::Exception in there?

pdet avatar Aug 10 '22 10:08 pdet

@Mause I've chatted with Mark about this, the reason to not use Duckdb exceptions is mainly due to their copying being unnecessarily complicated.

In this case, maybe we should create a struct of QueryResultException in the query result which propagates the Exception Type, and then we avoid the exception reconstruction.

pdet avatar Aug 10 '22 16:08 pdet

@Mause I've chatted with Mark about this, the reason to not use Duckdb exceptions is mainly due to their copying being unnecessarily complicated.

In this case, maybe we should create a struct of QueryResultException in the query result which propagates the Exception Type, and then we avoid the exception reconstruction.

That seems reasonable, though we do still have to reconstruct the exceptions in that case, though we can remove the string splitting

Mause avatar Aug 11 '22 04:08 Mause

Thanks for the PR!

First of all I really like the changes to the tests! However the hydrated exceptions make a couple of assumptions that might not hold true for all error messages (as not all error messages are created from a caught Exception)

The current situation is definitely an issue, and I appreciate you bringing attention to it, but this is part of a wider issue in the codebase that affects more than just the Python client.

I've raised a PR(#4371) that addresses this issue at the root, rather than at the tail-end of it.

Tishj avatar Aug 13 '22 11:08 Tishj

@Tishj what's your plan with regards to all the tests? Are you planning to merge without updating them all as I have done here?

Mause avatar Aug 14 '22 11:08 Mause

@Tishj what's your plan with regards to all the tests? Are you planning to merge without updating them all as I have done here?

I was thinking of taking the best of both, merging your test changes into my PR, if that's okay with you

Tishj avatar Aug 14 '22 11:08 Tishj

@Tishj what's your plan with regards to all the tests? Are you planning to merge without updating them all as I have done here?

I was thinking of taking the best of both, merging your test changes into my PR, if that's okay with you

If they all still pass, feel free to cherry pick them across

Mause avatar Aug 14 '22 13:08 Mause

Closed in favour of changes copied to https://github.com/duckdb/duckdb/pull/4371

Mause avatar Aug 18 '22 09:08 Mause