Skip to content

Feature Request: Programmatically Cancel Convex Transactions Without Throwing Exceptions #210

@doichev-kostia

Description

@doichev-kostia

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()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions