Skip to content
This repository has been archived by the owner on Jul 3, 2019. It is now read-only.

"err.code.match is not a function" after a failed git clone #169

Closed
parties opened this issue Feb 4, 2019 · 10 comments
Closed

"err.code.match is not a function" after a failed git clone #169

parties opened this issue Feb 4, 2019 · 10 comments

Comments

@parties
Copy link

parties commented Feb 4, 2019

I discovered this bug while using NPM to clone a private git repository and the clone failed (ssh_exchange_identification: Connection closed by remote host, could be a rate-limit issue from our internal server).

Error log from npm i --verbose:

npm verb stack TypeError: err.code.match is not a function
npm verb stack     at BB.try.catch.err (/Users/[REDACTED]/.nvm/versions/node/v8.14.0/lib/node_modules/npm/node_modules/pacote/lib/with-tarball-stream.js:110:55)
npm verb stack     at tryCatcher (/Users/[REDACTED]/.nvm/versions/node/v8.14.0/lib/node_modules/npm/node_modules/bluebird/js/release/util.js:16:23)
npm verb stack     at Promise._settlePromiseFromHandler (/Users/[REDACTED]/.nvm/versions/node/v8.14.0/lib/node_modules/npm/node_modules/bluebird/js/release/promise.js:512:31)
npm verb stack     at Promise._settlePromise (/Users/[REDACTED]/.nvm/versions/node/v8.14.0/lib/node_modules/npm/node_modules/bluebird/js/release/promise.js:569:18)
npm verb stack     at Promise._settlePromise0 (/Users/[REDACTED]/.nvm/versions/node/v8.14.0/lib/node_modules/npm/node_modules/bluebird/js/release/promise.js:614:10)
npm verb stack     at Promise._settlePromises (/Users/[REDACTED]/.nvm/versions/node/v8.14.0/lib/node_modules/npm/node_modules/bluebird/js/release/promise.js:690:18)
npm verb stack     at _drainQueueStep (/Users/[REDACTED]/.nvm/versions/node/v8.14.0/lib/node_modules/npm/node_modules/bluebird/js/release/async.js:138:12)
npm verb stack     at _drainQueue (/Users/[REDACTED]/.nvm/versions/node/v8.14.0/lib/node_modules/npm/node_modules/bluebird/js/release/async.js:131:9)
npm verb stack     at Async._drainQueues (/Users/[REDACTED]/.nvm/versions/node/v8.14.0/lib/node_modules/npm/node_modules/bluebird/js/release/async.js:147:5)
npm verb stack     at Immediate.Async.drainQueues (/Users/[REDACTED]/.nvm/versions/node/v8.14.0/lib/node_modules/npm/node_modules/bluebird/js/release/async.js:17:14)
npm verb stack     at runCallback (timers.js:810:20)
npm verb stack     at tryOnImmediate (timers.js:768:5)
npm verb stack     at processImmediate [as _immediateCallback] (timers.js:745:5)
npm verb cwd /Users/[REDACTED]
npm verb Darwin 18.2.0
npm verb argv "/Users/[REDACTED]/.nvm/versions/node/v8.14.0/bin/node" "/Users/[REDACTED]/.nvm/versions/node/v8.14.0/bin/npm" "i" "--verbose"
npm verb node v8.14.0
npm verb npm  v6.7.0
npm ERR! err.code.match is not a function

Unfortunately I don't know how to reproduce the bug in an environment outside our internal network (since it requires the remote host to close the connection).

Error message from inspecting err.cause.message in the Node debugger:

Command failed: git clone --mirror -q git@[REDACTED].git /Users/[REDACTED]/.npm/_cacache/tmp/git-clone-c6ce09c3/.git
warning: templates not found /var/folders/6d/t0qr1_gx7zngvgvtpbd6bg8wsq82z0/T/pacote-git-template-tmp/git-clone-6acc9b69
ssh_exchange_identification: Connection closed by remote host
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

I can confirm that I do have access to the repository, and running npm i will sometimes pass without any errors (which leads me to believe it's a rate-limit issue on our side).


Cause: it is coming from this line of code within with-tarball-stream.js.

if (opts.cache && err.code && !err.code.match(/^E\d{3}$/)) { ... }

The issue is that err.code is a Number, not a String, and the Number prototype does not have a match function.

I would assume the easiest fix would be to simply interpret the code as a String and match from there:

if (opts.cache && err.code && !String(err.code).match(/^E\d{3}$/)) {

Thoughts?

@rkaw92
Copy link

rkaw92 commented Mar 21, 2019

Confirmed - this still appears to be an issue in 6.9.0. Not sure yet what the underlying error is, since it is getting masked by the bug.

@michaellopez
Copy link

michaellopez commented Apr 8, 2019

I got hit by this too. Lost internet connection during and npm install. So that might be a way to trigger the bug, npm install and manually disconnect computer from the internet.

npm -v
6.9.0
node -v
v10.15.3

@michaellopez
Copy link

Forgot to say that I only use npm, not pacote.

@parties
Copy link
Author

parties commented Apr 16, 2019

Forgot to say that I only use npm, not pacote.

pacote is a dependency of npm (package.json).

@BigB007
Copy link

BigB007 commented May 30, 2019

Issue still persists. Have anyone found the solution?

Cause: it is coming from this line of code within with-tarball-stream.js.

if (opts.cache && err.code && !err.code.match(/^E\d{3}$/)) { ... }

@parties
Copy link
Author

parties commented May 30, 2019

#170 aims to fix this.

@piyushjain90
Copy link

@parties when #170 will be merged?

@thundron
Copy link

thundron commented Jun 3, 2019

+1 on this

@parties
Copy link
Author

parties commented Jun 3, 2019

@parties when #170 will be merged?

Not yet, you can watch the PR for more details.

I approved the changes, but I don't have permissions to merge, so we'll have to wait for official approval.

@parties
Copy link
Author

parties commented Jun 17, 2019

#170 is merged!

@parties parties closed this as completed Jun 17, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants