Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

nice error on nested triggers #348

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

Open
ldanilek wants to merge 1 commit into main
base: main
Choose a base branch
Loading
from lee/error-on-nested-triggers

Conversation

@ldanilek
Copy link
Contributor

@ldanilek ldanilek commented Nov 20, 2024


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

}),
).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

Reviewers

1 more reviewer

@sshader sshader sshader left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

AltStyle によって変換されたページ (->オリジナル) /