entering the literals of a v.union() when using run function in dashboard
When running functions through the dashboard, i can't seem to figure out how to manually type the value of a
v.union(v.literal("easy"), v.literal("medium"), v.literal("hard"))
when i enter the value i just want as a string "hard" i get an error.
The function i try to run via the dashboard (the type field is a v.union aswell as the difficulty)
8 Replies
the mismatch isn't coming from the "difficulty" union, which you are using correctly. It's from the
thumbnail: v.optional(v.id("_storage"))
which you are passing in as thumbnail: ""
. The empty string is not a valid storage id. I think you probably want to remove the thumbnail
key from the input entirely.Ohh damn i completely missed that, i couldn't interpreate that from the error
Thanks Lee! may i ask how u could tell that? I'd like to be able to better read the errors in the future
Hmm actually still getting the error on web too after making a form for it:
failure
ArgumentValidationError: Value does not match validator.
Path: .activity
Value: {details: {description: "llqwkldkqwdmkqwdkl", difficulty: "easy", rewardPoints: 200.0, thumbnailId: "", title: "qwdqwkdk"}, type: "challenge"}
Validator: v.union(v.object({details: v.object({description: v.optional(v.string()), difficulty: v.union(v.literal("easy"), v.literal("medium"), v.literal("hard")), rewardPoints: v.float64(), thumbnailId: v.optional(v.id("_storage")), title: v.string()}), type: v.literal("challenge")}), v.object({details: v.object({description: v.optional(v.string()), difficulty: v.union(v.literal("easy"), v.literal("medium"), v.literal("hard")), rewardPoints: v.float64(), thumbnailId: v.optional(v.id("_storage")), title: v.string()}), steps: v.array(v.object({text: v.string(), thumbnail: v.optional(v.id("_storage")), timeCode: v.optional(v.string())})), type: v.literal("tutorial")}), v.object({details: v.object({description: v.optional(v.string()), difficulty: v.union(v.literal("easy"), v.literal("medium"), v.literal("hard")), rewardPoints: v.float64(), thumbnailId: v.optional(v.id("_storage")), title: v.string()}), questions: v.array(v.object({answers: v.array(v.object({answer: v.string(), isCorrect: v.boolean()})), question: v.string()})), type: v.literal("quiz")}), v.null())
I looked through each field and compared the value to the validator. So i noticed that thumbnail didn't match
This is the schema for context:
The thumbnailId is optional (just changed the name to thumbnailId, to not add confusion from original post)
Ahh nvm
The error message says that thumbnailId is still the empty string
Yeah i can tell now. And found the issue. I ended up adding thumbnailId: "" in the defaultValues of my react-hook-form
Thanks again, enjoyr ur sunday
sg glad you figured it out
Yeah, sometimes it's worth actually reading through and understanding the errors before jumping to conclusion somethings else is the root cause haha. Something i def try to get better at. I could have easily spent more time than needed on finding the solution had i not asked here haha