corepack icon indicating copy to clipboard operation
corepack copied to clipboard

Unhandled Exception leading to Ambiguous and Unhelpful 404 Error | Corepack

Open jeremiah-snee-openx opened this issue 3 years ago • 3 comments

Version

v18.12.0

Platform

Darwin MBPM1-OP-43 21.6.0 Darwin Kernel Version 21.6.0: Mon Aug 22 20:19:52 PDT 2022; root:xnu-8020.140.49~2/RELEASE_ARM64_T6000 arm64

Subsystem

corepack

What steps will reproduce the bug?

Open Existing node project

Add "packageManager": "[email protected]", to package.json

Run in terminal rm -rf node_modules corepack enable corepack prepare pnpm@latest --activate pnpm install or pnpm version

How often does it reproduce? Is there a required condition?

Anytime invalid package version used for PNPM

What is the expected behavior?

Handle Error with helpful response. e.g.

Invalid Package.Json:112 config for packageManager. Requested pnpm version 7.13.14 is invalid "packageManager": "[email protected]",

What do you see instead?

Unhandled, Ambiguous and Unhelpful Error.

Internal Error: Server answered with HTTP 404
    at ClientRequest.<anonymous> (/Users/jeremiah.snee/.asdf/installs/nodejs/18.12.0/lib/node_modules/corepack/dist/corepack.js:16060:31)
    at Object.onceWrapper (node:events:628:26)
    at ClientRequest.emit (node:events:513:28)
    at HTTPParser.parserOnIncomingClient (node:_http_client:693:27)
    at HTTPParser.parserOnHeadersComplete (node:_http_common:117:17)
    at TLSSocket.socketOnData (node:_http_client:534:22)
    at TLSSocket.emit (node:events:513:28)
    at addChunk (node:internal/streams/readable:324:12)
    at readableAddChunk (node:internal/streams/readable:297:9)
    at Readable.push (node:internal/streams/readable:234:10) 

Additional information

Simple Fix.

Check https://registry.npmjs.org/pnpm for valid matching version before creating http request.

jeremiah-snee-openx avatar Nov 01 '22 01:11 jeremiah-snee-openx

I can reproduce.

mkdir repro
cd repro
echo '{"packageManager": "[email protected]"}' > package.json
corepack pnpm version
cd ..
rm -r repro

Would you like to send a PR to fix this?

aduh95 avatar Nov 01 '22 02:11 aduh95

Sure thing.

Will fork and create PR.

jeremiah-snee-openx avatar Nov 01 '22 03:11 jeremiah-snee-openx

+1

DLLluoluo avatar Mar 22 '23 11:03 DLLluoluo