Skip to content

Propagate errors across all results in a transaction #973

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

Merged
merged 4 commits into from
Oct 9, 2023

Conversation

robsdedude
Copy link
Member

A new error ResultFailedError is introduced. It will be raised when using a Result object after the result or another result in the same transaction has failed.

User code would only ever run into this situation when catch exceptions and deciding to ignore them. Now, an error will be raised instead of undefined behavior. The undefined behavior before this fix could be (among other things) protocol violations, incomplete summary data, and hard to interpret errors.

Depends on:

A new error `ResultFailedError` is introduced. It will be raised when using
a `Result` object after the result or another result in the same transaction
has failed.

User code would only ever run into this situation when catch exceptions and
deciding to ignore them. Now, an error will be raised instead of undefined
behavior. The undefined behavior before this fix could be (among other things)
protocol violations, incomplete summary data, and hard to interpret errors.
Copy link
Contributor

@bigmontz bigmontz left a comment

Choose a reason for hiding this comment

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

💯

(However, It might be good to have some unit tests :D )

@@ -1946,6 +1948,9 @@ Client-side errors
:show-inheritance:
:members: result

.. autoexception:: neo4j.exceptions.ResultFailedError()
Copy link
Contributor

Choose a reason for hiding this comment

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

Understand if we have settled on a common name for this already. but is this error indicative what is actually wrong? "The result failed" is very vague, would something like: TransactionInvalidStateError be a bit more explanative?
if the detail message could be:
The transaction that contains this result has encountered error, all results in this transaction are therefore invalid. if you could attach the transaction to the error so users can access it that could be useful for debugging

Copy link
Member Author

@robsdedude robsdedude Oct 6, 2023

Choose a reason for hiding this comment

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

We have not defined what exact error should be thrown. So this sure is up for debate.

However, there is more detail to this massage:

The error name is purposefully vague because it can have multiple reasons why the result would throw it:

  • The result in question failed but the user ignored it and kept using the result
  • A different result in the same transaction failed but the user ignored it

In either case, the raise ResultFailedError(...) from ... here (specifically the from bit) will make the error say something like "this is a direct cause of <insert original error with stack trace>".

Copy link
Contributor

@thelonelyvulpes thelonelyvulpes Oct 6, 2023

Choose a reason for hiding this comment

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

Thanks, should we consider exposing a property isFailed:boolean on the result? Whether that is in this change or subsequent one.

@robsdedude robsdedude merged commit ace72e9 into neo4j:5.0 Oct 9, 2023
@robsdedude robsdedude deleted the fix-transaction-lifetime branch October 9, 2023 15:16
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