danielyogel
danielyogel•12h ago

Error Messsage for 'discriminated union' DB update

Hey! I try to insert into a table with discriminated union, and the error details are missing from the log. Anything I can do about it? The log only show the object validated and the validator definition, and I see no difference between them.
10 Replies
Convex Bot
Convex Bot•12h 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!
Clever Tagline
Clever Tagline•11h ago
Please share more details. The logs you're seeing would be good, as well as snippets from the related code. BTW, is this the "small question" that somehow didn't appear in your other thread?
danielyogel
danielyogelOP•11h ago
@Clever Tagline Which other thread?
danielyogel
danielyogelOP•11h ago
oops, mistake 🙂
Clever Tagline
Clever Tagline•11h ago
No worries. I'll delete the post to avoid confusion.
danielyogel
danielyogelOP•10h ago
Thanks, anyway: I see "Value does not match validator." error message when inserting into a table of union type, just like this one: https://docs.convex.dev/database/schemas#unions The message regarding which path fails does not appear. So the first question is, can I make the error more verbose? This is even more important for me than fixing the error itself, because I try to debug it for an hour.
Clever Tagline
Clever Tagline•10h ago
I don't think so. If it's a validation error, I don't believe that there's a way to intercept that and provide more detail. The best you can do is add an issue to the Convex repo asking for more verbose validation errors, but that won't help your current problem.
danielyogel
danielyogelOP•10h ago
The value exist somewhere, the validator and value are printed, so I run them together locally I will open an issue. Anyway, looks like Convex validator is really bugy when working with unions... will provide an example. import { v } from 'convex/values'; import { validate } from 'convex-helpers/validators'; const value = { status: 'complete', wrongField: 'a' }; const validator = v.union( v.object({ status: v.literal('initialized'), updatedAt: v.float64() }), v.object({ status: v.literal('loading'), work: v.optional(v.string()) }), v.object({ status: v.literal('complete'), content: v.string() }), v.object({ status: v.literal('error'), errorMessage: v.string() }) ); validate(validator, value, { throw: true, allowUnknownFields: true }); ValidationError: Validator error for status: Expected error, got "complete" expected: "error", got: ""complete"", path: "status", This is a wrong error message... @Clever Tagline Ok, I 100% the problem, I try to update an object with it's _id, _creationTime and the validator throws becaues "allowUnknownFields" is set to 'false' by Convex, and I think there's no way to change that. The second problem is a bug: the error message thrown is not related to the problem. That's a bug in the validator.
Clever Tagline
Clever Tagline•3h ago
Yeah, definitely open an issue for that second problem. As for the first, could you share a more detailed example of the code that's trying to perform the update?

Did you find this page helpful?