Skip to content

fix: show better error when encountering external catalog protocol usage#8254

Merged
zkochan merged 3 commits intomainfrom
gluxon/catalog-error-on-external-catalog-usage-better-error
Jun 30, 2024
Merged

fix: show better error when encountering external catalog protocol usage#8254
zkochan merged 3 commits intomainfrom
gluxon/catalog-error-on-external-catalog-usage-better-error

Conversation

@gluxon
Copy link
Copy Markdown
Member

@gluxon gluxon commented Jun 28, 2024

Problem

I'm predicting a common problem with the catalog: protocol will be users running npm publish instead of pnpm publish. I'd like to make errors related to this mistake more clear.

Changes

Before

Screenshot 2024-06-28 at 1 16 47 AM

After

Screenshot 2024-06-28 at 1 41 04 AM

// encountered this deep into resolution, it's likely because it's an out of
// repo dependency that was published incorrectly. For example, it may be
// been mistakenly published with 'npm publish' instead of 'pnpm publish'.
if (wantedDependency.pref.startsWith('catalog:')) {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a convenient place to throw an error since the catch block sets up pkgsStack, but let me know if we think this error should be thrown somewhere else.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe do the check only when there's an error.

Copy link
Copy Markdown
Member Author

@gluxon gluxon Jun 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if we should reuse existing ERR_PNPM_SPEC_NOT_SUPPORTED_BY_ANY_RESOLVER error instead and detect if the specifier that was unsupported was the catalog: protocol. I realized this might be simpler after looking at this code more today.

I just pushed up this approach as 438d0b9, which removes the throw inside resolveDependencies.ts entirely.

What do you think?

Screenshot 2024-06-29 at 12 37 22 AM

@gluxon gluxon marked this pull request as ready for review June 28, 2024 06:29
@gluxon gluxon requested a review from zkochan as a code owner June 28, 2024 06:29
@gluxon gluxon force-pushed the gluxon/catalog-error-on-external-catalog-usage-better-error branch from 622f29c to 438d0b9 Compare June 29, 2024 04:45
})
return null
}
err.package = wantedDependencyDetails
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing I don't like is that these error objects aren't typed, but we could refactor that general problem in a future PR.

@gluxon
Copy link
Copy Markdown
Member Author

gluxon commented Jun 29, 2024

Thanks for catching those typos.

@zkochan zkochan merged commit 9bf9f71 into main Jun 30, 2024
@zkochan zkochan deleted the gluxon/catalog-error-on-external-catalog-usage-better-error branch June 30, 2024 07:53
@gluxon gluxon mentioned this pull request Jul 7, 2024
18 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants