Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Intersection results could not be merged" does not mention the cause #3175

Closed
JoshuaKGoldberg opened this issue Jan 23, 2024 · 1 comment
Closed

Comments

@JoshuaKGoldberg
Copy link

Zod is great and I'm enjoying the features around intersecting/merging objects. But for .and, when the intersections results can't be merged for some reason, the error message thrown at runtime doesn't provide any details.

An error occurred.

Intersection results could not be merged

Stack Trace

ZodError: [
  {
    "code": "invalid_intersection_types",
    "path": [],
    "message": "Intersection results could not be merged"
  }
]
    at get error [as error] (file:///Users/josh/repos/dot-com/node_modules/.pnpm/zod@3.22.4/node_modules/zod/lib/index.mjs:538:31)
    at ZodIntersection.parse (file:///Users/josh/repos/dot-com/node_modules/.pnpm/zod@3.22.4/node_modules/zod/lib/index.mjs:638:22)
    at /Users/josh/repos/dot-com/src/pages/rss.xml.ts:26:48
    at Array.map (<anonymous>)

Not sure if this is a bug report or feature request, but: could the error message also include which field(s) are problematic?

Note that I'm not trying to report that the error is wrong. The error may be right - it just informative enough to explain why clearly.

Sorry that I'm not familiar enough with Zod to provide a standalone reproduction (I tried the Stackblitz Astro starter but couldn't get past TypeScript errors, amusingly). But here's how to get it on a real world project:

git clone https://github.com/JoshuaKGoldberg/dot-com
cd dot-com
git checkout 708081f # ncu-u-for-vite-5 branch
pnpm i
pnpm dev
open http://localhost:4321/rss.xml
@JacobWeisenburger
Copy link
Contributor

from what I can see the problem code is this:

import { rssSchema } from "@astrojs/rss"

const rssSchemaStrict = rssSchema.and(
    z.object( {
        link: z
            .string()
            .transform( ( link ) =>
                link.replace( /^src\/content/, "" ).replace( /index.mdx$/, "" ),
            ),
        pubDate: z.date(),
        title: z.string(),
    } ),
)

it seems that rssSchema is of type ZodEffect, so that means it has a transform or something at the end of the schema which makes it not an object schema, which means it can't be used with .and()

I suggest you use the schema from here instead:
https://github.com/withastro/astro/blob/main/packages/astro-rss/src/schema.ts

If you found my answer satisfactory, please consider supporting me. Even a small amount is greatly appreciated. Thanks friend! 🙏
https://github.com/sponsors/JacobWeisenburger

Repository owner locked and limited conversation to collaborators Jan 27, 2024
@JacobWeisenburger JacobWeisenburger converted this issue into discussion #3194 Jan 27, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Projects
None yet
Development

No branches or pull requests

2 participants