David Alonso
David Alonso5mo ago

Zod .describe() causing issues with schema validation

I'm seeing the following when running npx convex dev
✖ Error: Unable to run schema validation on https://sensible-salmon-524.convex.cloud
[CONVEX] Error fetching POST https://sensible-salmon-524.convex.cloud/api/prepare_schema 400 Bad Request: Error: Hit an error while evaluating your schema:
[CONVEX] Uncaught TypeError: Cannot read properties of undefined (reading 'describe')
[CONVEX] at <anonymous> (../types/fireview/filters/zod.ts:62:12)
✖ Error: Unable to run schema validation on https://sensible-salmon-524.convex.cloud
[CONVEX] Error fetching POST https://sensible-salmon-524.convex.cloud/api/prepare_schema 400 Bad Request: Error: Hit an error while evaluating your schema:
[CONVEX] Uncaught TypeError: Cannot read properties of undefined (reading 'describe')
[CONVEX] at <anonymous> (../types/fireview/filters/zod.ts:62:12)
The code in that file looks like this:
export const zFireviewWhereFilter = z.object({
value: z.union([
z
.object({
type: z.literal("static"),
value: z
.any()
.describe(
"The static value to filter on. This should match the type of the field."
),
})
.describe("A filter value that is a static value"),
z
.object({
type: z.literal("dynamic"),
queryValue: z.union([
zDocumentFieldFromPathQuery.describe(
"Used when the dynamic value is a field from a document."
),
zFirstNDocumentFieldsQuery.describe(
"Used when the dynamic value is a list of fields from several documents."
),
zDocumentFieldAggregationQuery.describe(
"Used when the dynamic value is an aggregation of a field."
),
]),
})
),
]),
});
export const zFireviewWhereFilter = z.object({
value: z.union([
z
.object({
type: z.literal("static"),
value: z
.any()
.describe(
"The static value to filter on. This should match the type of the field."
),
})
.describe("A filter value that is a static value"),
z
.object({
type: z.literal("dynamic"),
queryValue: z.union([
zDocumentFieldFromPathQuery.describe(
"Used when the dynamic value is a field from a document."
),
zFirstNDocumentFieldsQuery.describe(
"Used when the dynamic value is a list of fields from several documents."
),
zDocumentFieldAggregationQuery.describe(
"Used when the dynamic value is an aggregation of a field."
),
]),
})
),
]),
});
This is put into a table like so:
v.object({
...vCommonFilterExpressionFields.fields,
...vFireviewWhereFilter.fields,
})
v.object({
...vCommonFilterExpressionFields.fields,
...vFireviewWhereFilter.fields,
})
where
export const vFireviewWhereFilter = zodToConvex(zFireviewWhereFilter);
export const vFireviewWhereFilter = zodToConvex(zFireviewWhereFilter);
When i remove the describe lines I don't see the same error so I'm wondering if zodToConvex is doing something weird
3 Replies
David Alonso
David AlonsoOP5mo ago
For context, i need those descriptions to reuse these data types in tools to agents so they have more context This issue might be related to #zodToConvex helper giving unintelligible errors due to circular dep issue, was just really not obvious - sharing in case anyone gets weird errors like this - was not a convex issue
jamwt
jamwt5mo ago
thanks for the follow up it's really a bummer how often circular issues cause some of the most confusing errors
David Alonso
David AlonsoOP5mo ago
yep, and there was nothing structurally wrong in my types graph, just had to reorganize files - kinda wish this could be done behind the scenes, but ofc this is beyond the scope of convex (for now haha)

Did you find this page helpful?