#Error Messsage for 'discriminated union' DB update

28 messages · Page 1 of 1 (latest)

vague abyss
#

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.

haughty warrenBOT
#

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](https://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!
vague abyss
#

Error Messsage for 'discriminated union' DB insert

#

Error Messsage for 'discriminated union' DB update

fresh wedge
#

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?

vague abyss
#

@fresh wedge Which other thread?

fresh wedge
vague abyss
#

oops, mistake 🙂

fresh wedge
#

No worries. I'll delete the post to avoid confusion.

vague abyss
#

Thanks, anyway:

#

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.

fresh wedge
#

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.

vague abyss
#

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...

#

@fresh wedge 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.

fresh wedge
#

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?

vague abyss
#

Feel free to take a look, Thanks!

fresh wedge
# vague abyss Feel free to take a look, Thanks!

Sorry, but I'm not Convex staff. None of the mods are. We help where we can, but we can't address issues ourselves. Our mod roles are just re: this server. Only users with the Convex logo by their name (the "Convex Team" role) are staff.

#

(While I could probably fork the repo and submit a fix as a PR, the inner workings of Convex are beyond my skills, so I wouldn't even know where to begin!)