David Alonso
David Alonso4w ago

Cannot store/validate `undefined` in array?

Just making sure I'm not missing something
8 Replies
Convex Bot
Convex Bot4w 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!
David Alonso
David AlonsoOP4w ago
If I pass something like ["a", "b", undefined] to a convex function, it doesn't get called but I also don't see any errors anywhere..
Clever Tagline
I know that undefined is scrubbed if passed as a single argument value to a function (more info from the Convex side in this thread), but I wouldn’t expect it to scrub an entire function call if a single array value is undefined.
ballingt
ballingt3w ago
@David Alonso How are you passing this? You should get an error like
> v.convexToJson({a: [1,2,undefined]})
Uncaught:
Error: undefined is not a valid Convex value (present at path .a[2] in original object {"a":[1,2,"undefined"]}). To learn about Convex's supported types, see https://docs.convex.dev/using/types.
at convexToJsonInternal (file:///Users/tomb/convex/npm-packages/convex/dist/esm/values/value.js:171:11)
at file:///Users/tomb/convex/npm-packages/convex/dist/esm/values/value.js:206:22
at Array.map (<anonymous>)
at convexToJsonInternal (file:///Users/tomb/convex/npm-packages/convex/dist/esm/values/value.js:205:18)
at convexToJsonInternal (file:///Users/tomb/convex/npm-packages/convex/dist/esm/values/value.js:232:16)
at Module.convexToJson (file:///Users/tomb/convex/npm-packages/convex/dist/esm/values/value.js:272:10)
> v.convexToJson({a: [1,2,undefined]})
Uncaught:
Error: undefined is not a valid Convex value (present at path .a[2] in original object {"a":[1,2,"undefined"]}). To learn about Convex's supported types, see https://docs.convex.dev/using/types.
at convexToJsonInternal (file:///Users/tomb/convex/npm-packages/convex/dist/esm/values/value.js:171:11)
at file:///Users/tomb/convex/npm-packages/convex/dist/esm/values/value.js:206:22
at Array.map (<anonymous>)
at convexToJsonInternal (file:///Users/tomb/convex/npm-packages/convex/dist/esm/values/value.js:205:18)
at convexToJsonInternal (file:///Users/tomb/convex/npm-packages/convex/dist/esm/values/value.js:232:16)
at Module.convexToJson (file:///Users/tomb/convex/npm-packages/convex/dist/esm/values/value.js:272:10)
ballingt
ballingt3w ago
However if you have a layer of indirection where you serialize the object yourself, it could be null:
No description
ampp
ampp3w ago
Is there any way possible to get a line number on where the error is, my system is so complex now i cant find these, it takes at least a hour of placing console logs. One time it was a query was getting a object when i was looking for a insert. Or is there some general way to protect all convex functions from this. 😅 Im wondering if one of my functions is serializing a field starting with a underscore.. ive been indecisive about this object design and its screwed me over ugg this one caught me again.. i now remember.. the mutation attempts to serialize my payload on the final return and if a sub sub object doesnt searlize right its mostly invisible to me. I don't use a return validator for performance reasons. I think what is making this so hard is that both the console.log below in the function never output anything: so as far as im concerned the code is breaking before, but its only fixed if i fix the returned data or return void.
console.log('END EVENT')
const eventData = Event.get() or new Event(oldEventData).get()
console.log('eventData', eventData)
return eventData
console.log('END EVENT')
const eventData = Event.get() or new Event(oldEventData).get()
console.log('eventData', eventData)
return eventData
Uncaught Error: BadObject {bad object data} To learn about Convex's supported types, see https://docs.convex.dev/using/types.
Clever Tagline
In your code snippet you have the literal word or instead of the "or" operator ||. Not sure if that could be contributing to any of the issues you're experiencing.
ampp
ampp3w ago
Yeah, its not that. I was just showing i had 2 ways of creating. I'd like to repo somehow, this has been the only time I've seen a error that prevents the console logs from outputting