npm / npm-registry-client

http://npm.im/npm-registry-client
ISC License
264 stars 108 forks source link

Print full URL in error message when it fails to load a module #144

Open Que3216 opened 8 years ago

Que3216 commented 8 years ago

This is related to: https://github.com/npm/npm/issues/11834

If you use artifactory for your npm registry then npm prints a rather confusing error message when it fails to load a module:

> npm install i-do-not-exist --registry https://somedomain/artifactory/api/npm/all-npm
npm ERR! 404 Not Found: artifactory
npm ERR! 404
npm ERR! 404  'artifactory' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.

The 'artifactory' name is incorrectly extracted at https://github.com/npm/npm-registry-client/blob/master/lib/request.js#L276.

This has been consistently confusing devs on our team, and makes to tricky to hunt down the offending node module.

Would you accept a PR that adds a line to the error message with the full URL? For example the above error message would now become:

> npm install i-do-not-exist --registry https://somedomain/artifactory/api/npm/all-npm
npm ERR! 404 Not Found: artifactory
npm ERR! 404 GET request for 'https://somedomain/artifactory/api/npm/all-npm/i-do-not-exist' returned a 404
npm ERR! 404
npm ERR! 404  'artifactory' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.
Que3216 commented 8 years ago

Pinging this ticket (@isaacs, @othiym23). Would you accept a PR to print the full URL?

ghost commented 8 years ago

Issue the PR! This error is killing me!

matthewwiesen commented 8 years ago

Running across this same issue.

Que3216 commented 7 years ago

Anyone with admin access to this repro willing to approve a PR?

Que3216 commented 7 years ago

(@iarna?)

jgeorgeson commented 7 years ago

So the error message is basically assuming that a certain part of the URL is the package name? Why not report the error with the package name that was used to construct the URL returning the 404, and leave the full URL as debug output? I don't really care what the full URL was on my first pass , I know what my configured registry URL is and I just want to know what dependency it couldn't find.

warandpeace commented 7 years ago

+1 This is causing issues for me as well, renders our npm artifactory mirror unusable.

zkat commented 7 years ago

Sorry I haven't responded to this one: this is fixed in npm@5 already (and even includes the version range that was requested, so you would see, like Not Found: i-do-not-exist@^5.

Parsing out the URL like this is super janky and just generally bound to be a pain. I'd rather do it "right" and pass in specifier information (which is what pacote does, and this what npm@5 does).

That's all in https://github.com/npm/npm/pull/15666

warandpeace commented 7 years ago

Awesome, thank you so much @zkat!!

zkat commented 7 years ago

@warandpeace see https://github.com/zkat/pacote/blob/latest/lib/fetchers/registry/fetch.js#L41-L44 for the code that does the magic