#ctx.runMutation failed
8 messages · Page 1 of 1 (latest)
I'd be happy to help you troubleshoot the ctx.runMutation error, but I need more information to provide specific guidance. Based on the knowledge sources, here are common issues and solutions:
Common Causes and Solutions
1. Using ctx.runMutation in Actions
When calling mutations from actions, you need to use the correct import path. The mutation reference should come from the generated API:
import { api } from "./_generated/api";
// ✅ Correct
await ctx.runMutation(api.myModule.myMutation, { args });
// ❌ Incorrect
await ctx.runMutation(myMutation, { args });
As shown in this example, you must import from _generated/api.
2. Context Type Issues
Make sure you're using ctx.runMutation in the right context:
- Actions: Can use
ctx.runMutation(Action context documentation) - Mutations: Can use
ctx.runMutationfor sub-transactions (Mutation context documentation) - Queries: Cannot use
ctx.runMutation
3. Error Handling
If your mutation is throwing errors, you can catch them:
try {
await ctx.runMutation(internal.myModule.myMutation, { args });
} catch (error) {
// Handle the error
console.error("Mutation failed:", error);
}
According to the error handling documentation, mutations can throw errors that need to be caught.
4. "use node" Runtime Issues
If you're using "use node" directive, be aware that calling functions from mutations won't run them in the Node environment, as noted in this Discord discussion.
To help you further, please provide:
- The exact error message you're seeing
- The code where you're calling
ctx.runMutation - The context (action, mutation, or query) where you're making the call
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@coral falcon Kapa.ai is still learning and improving, please let me know how I did by reacting below.
Let me check the knowledge base for you again. One moment! :books:
I'd be happy to help you debug the ctx.runMutation issue, but I don't see any code attached to your message.
To assist you effectively, please share:
- The code where you're calling
ctx.runMutation - The exact error message you're receiving
- The context - whether this is in an action, mutation, or query
You can paste the code directly in your next message, and I'll analyze it based on Convex best practices and help identify the issue.
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@coral falcon Kapa.ai is still learning and improving, please let me know how I did by reacting below.
Let me check the knowledge base for you again. One moment! :books: