-
Notifications
You must be signed in to change notification settings - Fork 455
Description
Description
I'm referring to the discord discussion (https://ptb.discord.com/channels/1019350475847499849/1382018814010724456),
which highlights issues with error handling and transaction rollbacks in Convex.
Currently, there is no idiomatic way to return a structured error without throwing an Exception.
There is a section in the Convex docs - "Application Errors"
that shows how to return an error
Returning different values
If you're using TypeScript different return types can enforce that you're handling error scenarios.
For example, a createUser mutation could return
Id<"users"> | { error: "EMAIL_ADDRESS_IN_USE" };
to express that either the mutation succeeded or the email address was already taken.
This ensures that you remember to handle these cases in your UI.
However, the problem in this scenario is that there is no way to programmatically cancel a transaction that runs within the mutation.
Therefore, if I want to have my queries or mutations to return Result<Data, Error>, I have to write the custom wrapper that throws the ConvexError in order for a mutation to be cancelled.
Question
Consequently, I would like to ask a question: Are there any plans to provide the API to cancel the transaction manually?
Proposed API
ctx.rollbackTransaction()