Skip to content

Handle package not found error when opening GitHub URLs #17

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

Merged

Conversation

tommy-mitchell
Copy link
Contributor

@tommy-mitchell tommy-mitchell commented Sep 1, 2023

When opening a non-existent NPM or Yarn package, npm-home will open a 404 page. When trying to open the same "package" on GitHub, npm-home throws a long error:

$ npm-home -g '~invalid~'
file:///.../npm-home/node_modules/package-json/index.js:72
			throw new PackageNotFoundError(packageName);
			      ^

PackageNotFoundError: Package `~invalid~` could not be found
    at packageJson (file:///.../npm-home/node_modules/package-json/index.js:72:10)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async openGitHub (file:///.../npm-home/cli.js:45:23)
    at async pMap.concurrency (file:///.../npm-home/cli.js:80:3)
    at async file:///.../npm-home/node_modules/p-map/index.js:139:20

This is because package-json throws:

npm-home/cli.js

Lines 45 to 46 in 7e2e51c

const packageData = await packageJson(name, {fullMetadata: true});
const {repository} = packageData;

This PR catches the PackageNotFoundError and logs a nicer message:

$ npm-home -g '~invalid~'
Package `~invalid~` doesn't exist!

The error message could likely be improved.

@sindresorhus sindresorhus merged commit 5fc422e into sindresorhus:main Sep 1, 2023
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