ampp
ampp8mo ago

Hard to trace error db.normalizeId

Error: [Request ID: 50fea7d41796b0d6] Server Error
Uncaught Error: Uncaught Error: Invalid arguments for `db.normalizeId`: invalid type: null, expected a string
at Promise.retrieve (../../../../node_modules/.pnpm/convex-ents@0.7.6_convex@1.12.0/node_modules/convex-ents/src/functions.ts:722:24)
at doc [as doc] (../../../../node_modules/.pnpm/convex-ents@0.7.6_convex@1.12.0/node_modules/convex-ents/src/functions.ts:1263:21)
at then [as then] (../../../../node_modules/.pnpm/convex-ents@0.7.6_convex@1.12.0/node_modules/convex-ents/src/functions.ts:1312:8)

at async handler (../../convex/clerkActions.ts:114:56)
Error: [Request ID: 50fea7d41796b0d6] Server Error
Uncaught Error: Uncaught Error: Invalid arguments for `db.normalizeId`: invalid type: null, expected a string
at Promise.retrieve (../../../../node_modules/.pnpm/convex-ents@0.7.6_convex@1.12.0/node_modules/convex-ents/src/functions.ts:722:24)
at doc [as doc] (../../../../node_modules/.pnpm/convex-ents@0.7.6_convex@1.12.0/node_modules/convex-ents/src/functions.ts:1263:21)
at then [as then] (../../../../node_modules/.pnpm/convex-ents@0.7.6_convex@1.12.0/node_modules/convex-ents/src/functions.ts:1312:8)

at async handler (../../convex/clerkActions.ts:114:56)
Not really a bug report but i was running a action that called a ctx.runMutation that then called a mutation function which by mistake had a ctx.viewerId that passed into another async function that probably failed at the getX for that user. This orginally worked via the web so it didn't get caught because they were authed. Using ents. I tried to run the function from console and a init script and got errors every time. But if i checked the act as user in console it still errored. What made it weird was line 114 was a empty line before the bad ctx.runMutation And every time i narrowed it down it was a empty line before the function running. And running the function directly that ctx.runMutation called gave the same error. Maybe this can save someone else the headache.
1 Reply
Michal Srb
Michal Srb8mo ago
Checking the logs for the Request ID might be also helpful when multiple functions are involved: https://docs.convex.dev/functions/debugging#finding-relevant-logs-by-request-id
Debugging | Convex Developer Hub
Debugging is the process of figuring out why your code isn't behaving as you