Data doesn't commit when re-throwing error
Just checking - is there any reason a convex validation error wouldn't get caught by a try/catch? I'm seeing an insert fail, and the validation error is correct, but the whole thing is wrapped in a try/catch, but the catch isn't happening.
Happening in an internal mutation in the convex runtime, function triggered via cli.
4 Replies
Where is the try/catch? Is this a Convex action calling a mutation? when you say "the whole thing is wrapped in a try/catch" I'm not sure what that means.
Almost the entire body of the mutation is within a try/catch, but that wasn't actually helpful info - main point is that the insert that's failing is inside of a try/catch, and I'm awaiting it. When it throws, the error is logged in convex logs, but the catch doesn't execute.
Basically:
The only thing in the console when it fails is the error. I was thinking it wasn't catching, but looking at it now it seems more likely that the log is from the rethrow.
But the patch doesn't happen, which I would expect to cause a separate error before the rethrow. Maybe the patch is failing silently?
Ah sorry for the delay — if a mutation throws an error, that aborts then whole transaction!
If you catch it this is fine, but if you re-throw it the entire transaction is rolled back.
Ah, right, it’s a transaction 🤦♂️🤦♂️
Thanks!