Kenny
Kenny7d ago

Incorrect invalid type error?

When I try to exectute the following code in a convex function:
export const updateAnimalVaccineList = mutationWithTriggers({
handler: async (ctx, args) => {
return await Promise.all(
[
{
expirationDate: "2028-07-25",
id: "n571fm2daz2w33w1mjqjbz812d7ts71p",
name: "Slovenian Chia Seeds Soup",
},
].map(({ id, ...rest }) => {
return ctx.db.patch(id as Id<"vaccines">, rest)
}),
)
},
})
export const updateAnimalVaccineList = mutationWithTriggers({
handler: async (ctx, args) => {
return await Promise.all(
[
{
expirationDate: "2028-07-25",
id: "n571fm2daz2w33w1mjqjbz812d7ts71p",
name: "Slovenian Chia Seeds Soup",
},
].map(({ id, ...rest }) => {
return ctx.db.patch(id as Id<"vaccines">, rest)
}),
)
},
})
I get the following error:
CONVEX M(vaccines:updateAnimalVaccineList)] [Request ID: 0ea6c4ad70528400] Server Error
Uncaught Error: undefined is not a valid Convex value (present at path [0] in original object ["undefined"]). To learn about Convex's supported types, see https://docs.convex.dev/using/types.
at convexToJsonInternal (../../node_modules/convex/src/values/value.ts:300:6)
at <anonymous> (../../node_modules/convex/src/values/value.ts:335:4)
at map [as map] (<anonymous>)
at convexToJsonInternal (../../node_modules/convex/src/values/value.ts:333:29)
at convexToJson (../../node_modules/convex/src/values/value.ts:430:0)
CONVEX M(vaccines:updateAnimalVaccineList)] [Request ID: 0ea6c4ad70528400] Server Error
Uncaught Error: undefined is not a valid Convex value (present at path [0] in original object ["undefined"]). To learn about Convex's supported types, see https://docs.convex.dev/using/types.
at convexToJsonInternal (../../node_modules/convex/src/values/value.ts:300:6)
at <anonymous> (../../node_modules/convex/src/values/value.ts:335:4)
at map [as map] (<anonymous>)
at convexToJsonInternal (../../node_modules/convex/src/values/value.ts:333:29)
at convexToJson (../../node_modules/convex/src/values/value.ts:430:0)
It works fine if I do the following:
export const updateAnimalVaccineList = mutationWithTriggers({
handler: async (ctx, args) => {
return await ctx.db.patch("n571fm2daz2w33w1mjqjbz812d7ts71p" as Id<"vaccines">, {
expirationDate: "2028-07-25",

name: "Slovenian Chia Seeds Soup",
})
// return await Promise.all(
// [
// {
// expirationDate: "2028-07-25",
// id: "n571fm2daz2w33w1mjqjbz812d7ts71p",
// name: "Slovenian Chia Seeds Soup",
// },
// ].map(({ id, ...rest }) => {
// return ctx.db.patch(id as Id<"vaccines">, rest)
// }),
// )
},
})
export const updateAnimalVaccineList = mutationWithTriggers({
handler: async (ctx, args) => {
return await ctx.db.patch("n571fm2daz2w33w1mjqjbz812d7ts71p" as Id<"vaccines">, {
expirationDate: "2028-07-25",

name: "Slovenian Chia Seeds Soup",
})
// return await Promise.all(
// [
// {
// expirationDate: "2028-07-25",
// id: "n571fm2daz2w33w1mjqjbz812d7ts71p",
// name: "Slovenian Chia Seeds Soup",
// },
// ].map(({ id, ...rest }) => {
// return ctx.db.patch(id as Id<"vaccines">, rest)
// }),
// )
},
})
NOTE: I'm using a promise.all above in the way as I am as a minimal example, in real life its an endpoint that takes a variable length vaccine list.
2 Replies
Convex Bot
Convex Bot7d ago
Thanks for posting in <#1088161997662724167>. Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets. - Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.) - Use search.convex.dev to search Docs, Stack, and Discord all at once. - Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI. - Avoid tagging staff unless specifically instructed. Thank you!
Kenny
KennyOP7d ago
Since all the convex types are actually valid, and the js code is valid, this should be valid?

Did you find this page helpful?