RJ
RJ8mo ago

Unable to execute internal action from dashboard or CLI

I've got an internal action which I use to invite users to my application. It accepts some parameters (emailAddress and userRole) and coordinates with Clerk to send an invitation email and add the user to the DB with the correct role. It was intended to be run exclusively from the dashboard (or the CLI via convex run, though the dashboard is generally much easier). However, I'm running into some odd issues attempting to execute it by either method. See attached screen recording for what happens when I try to execute it via the dashboard. When I try to execute it via the CLI, I'm getting a validation error that I'm not sure I believe (scrubbed of some irrelevant data/PII):
$ pnpm doppler run --command="pnpm convex run --prod scripts/operational/inviteUser '{
\"emailAddress\": \"name@website.com\",
\"userRole\": { \"tag\": \"BrandPartner\", \"brandPartnerId\": \"xxx\" }
}'"
Using DOPPLER_CONFIG_DIR from the environment. To disable this, use --no-read-env.
✖ Failed to run function "scripts/operational/inviteUser":
Error: [Request ID: a802de57bfc6abaa] Server Error
ArgumentValidationError: Value does not match validator.
Path: .userRole
Value: {brandPartnerId: "xxx", tag: "BrandPartner"}
Validator: v.union(v.object({tag: v.literal("Internal")}), v.object({brandPartnerId: v.id("brandPartners"), tag: v.literal("BrandPartner")}), v.object({relationships: v.array(v.object({brandPartnerId: v.id("brandPartners"), retailer: v.union(...)})), tag: v.literal("SalesRep")}))
$ pnpm doppler run --command="pnpm convex run --prod scripts/operational/inviteUser '{
\"emailAddress\": \"name@website.com\",
\"userRole\": { \"tag\": \"BrandPartner\", \"brandPartnerId\": \"xxx\" }
}'"
Using DOPPLER_CONFIG_DIR from the environment. To disable this, use --no-read-env.
✖ Failed to run function "scripts/operational/inviteUser":
Error: [Request ID: a802de57bfc6abaa] Server Error
ArgumentValidationError: Value does not match validator.
Path: .userRole
Value: {brandPartnerId: "xxx", tag: "BrandPartner"}
Validator: v.union(v.object({tag: v.literal("Internal")}), v.object({brandPartnerId: v.id("brandPartners"), tag: v.literal("BrandPartner")}), v.object({relationships: v.array(v.object({brandPartnerId: v.id("brandPartners"), retailer: v.union(...)})), tag: v.literal("SalesRep")}))
7 Replies
ballingt
ballingt8mo ago
Does making this a named function change anything? I'm imagining default exports are less well tested man I wish our validators were pretty-printed in errors!
Validator:
v.union(
v.object({
tag: v.literal("Internal")
}),
v.object({
brandPartnerId: v.id("brandPartners"),
tag: v.literal("BrandPartner")
}),
v.object({
relationships: v.array(v.object({
brandPartnerId: v.id("brandPartners"),
retailer: v.union(...)
})),
tag: v.literal("SalesRep")
}))
Validator:
v.union(
v.object({
tag: v.literal("Internal")
}),
v.object({
brandPartnerId: v.id("brandPartners"),
tag: v.literal("BrandPartner")
}),
v.object({
relationships: v.array(v.object({
brandPartnerId: v.id("brandPartners"),
retailer: v.union(...)
})),
tag: v.literal("SalesRep")
}))
RJ
RJOP8mo ago
That seems to work!
ballingt
ballingt8mo ago
The dashboard, or from the CLI?
RJ
RJOP8mo ago
FYI, I do know this has worked in the past as a default export From the dashboard
sshader
sshader8mo ago
For the dashboard, I'd venture a guess that we're not handling well that you have a file called inviteUser (with a default export) as well as a directory called inviteUser
RJ
RJOP8mo ago
Also now works from the CLI! This is a pattern I've been trying out sometimes, for things like scripts—having a single file entrypoint with a default export, and then supporting Convex functions (and in theory other code) in a directory of the same name (i.e. in that entrypoint function's namespace)
sshader
sshader8mo ago
Yeah I don't know a reason why that pattern wouldn't work in general, but I'd guess we have a dashboard bug here (and maybe a npx convex run bug too, who knows). Will investigate.