Skip to content

Conversation

@ldanilek
Copy link
Contributor


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@ldanilek ldanilek requested a review from sshader November 20, 2024 16:31
}),
).rejects.toThrow(
new RegExp(
`Triggers\\.wrapDB called multiple times in a single mutation\\.\\s+` +
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I'd be less aggressive on the regex because I find it annoying to have to update the test whenever the error message changes. Maybe just checking the first sentence + checking a link to docs shows up in there somewhere?

wrapDB = <C extends Ctx>(ctx: C): C => {
if (wrapDBCalled) {
throw new Error(
`Triggers.wrapDB called multiple times in a single mutation. Not allowed due to potential deadlock.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this could merit a specific example of what this looks like, maybe just in the triggers docs? And we could link to it from the error message?

Like

Troubleshooting: Triggers.wrapDB called multiple times in a single mutation

This usually happens if a mutation is directly calling another mutation, for instance:

export const joinTeam = mutation(...) export const createTeam = mutation({	handler: (ctx) => {	const currentUserId = // load from auth	const team = await ctx.db.insert("teams", { creatorId: currentUserId, ... })	// ❌ This creates a new `Triggers` since it's calling another mutation	await joinTeam({ teamId })	} }) 

See for the recommended pattern.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants