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

Fix "TypeError: err.code.match is not a function" error #170

Merged
merged 1 commit into from Jun 17, 2019
Merged

Fix "TypeError: err.code.match is not a function" error #170

merged 1 commit into from Jun 17, 2019

Conversation

jviotti
Copy link
Contributor

@jviotti jviotti commented Feb 4, 2019

I hit this on CI running npm v6.7.0 a couple times, and then the error
went away before I could find out what the root cause was, but the issue
sounds worth resolving anyways.

Here is the stacktrace I could recover:

npm info teardown Done in 0s
npm verb stack TypeError: err.code.match is not a function
npm verb stack     at BB.try.catch.err (/usr/lib/node_modules/npm/node_modules/pacote/lib/with-tarball-stream.js:110:55)
npm verb stack     at tryCatcher (/usr/lib/node_modules/npm/node_modules/bluebird/js/release/util.js:16:23)
npm verb stack     at Promise._settlePromiseFromHandler (/usr/lib/node_modules/npm/node_modules/bluebird/js/release/promise.js:512:31)
npm verb stack     at Promise._settlePromise (/usr/lib/node_modules/npm/node_modules/bluebird/js/release/promise.js:569:18)
npm verb stack     at Promise._settlePromise0 (/usr/lib/node_modules/npm/node_modules/bluebird/js/release/promise.js:614:10)
npm verb stack     at Promise._settlePromises (/usr/lib/node_modules/npm/node_modules/bluebird/js/release/promise.js:690:18)
npm verb stack     at _drainQueueStep (/usr/lib/node_modules/npm/node_modules/bluebird/js/release/async.js:138:12)
npm verb stack     at _drainQueue (/usr/lib/node_modules/npm/node_modules/bluebird/js/release/async.js:131:9)
npm verb stack     at Async._drainQueues (/usr/lib/node_modules/npm/node_modules/bluebird/js/release/async.js:147:5)
npm verb stack     at Immediate.Async.drainQueues (/usr/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 /usr/src/app
npm verb Linux 4.13.0-25-generic
npm verb argv "/usr/bin/node" "/usr/bin/npm" "ci" "--verbose"
npm verb node v8.15.0
npm verb npm  v6.7.0
npm ERR! err.code.match is not a function
npm verb exit [ 1, true ]

Signed-off-by: Juan Cruz Viotti jv@jviotti.com

@jviotti
Copy link
Contributor Author

jviotti commented Apr 9, 2019

Ping @zkat :)

@@ -107,7 +107,7 @@ function withTarballStream (spec, opts, streamHandler) {
// Retry once if we have a cache, to clear up any weird conditions.
// Don't retry network errors, though -- make-fetch-happen has already
// taken care of making sure we're all set on that front.
if (opts.cache && err.code && !err.code.match(/^E\d{3}$/)) {
if (opts.cache && err.code && err.code.match && !err.code.match(/^E\d{3}$/)) {
Copy link

Choose a reason for hiding this comment

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

This doesn't catch the case where err.code is a number; I think this might be a more effective check:

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. Done!

I hit this on CI running npm v6.7.0 a couple times, and then the error
went away before I could find out what the root cause was, but the issue
sounds worth resolving anyways.

Here is the stacktrace I could recover:

```
npm info teardown Done in 0s
npm verb stack TypeError: err.code.match is not a function
npm verb stack     at BB.try.catch.err (/usr/lib/node_modules/npm/node_modules/pacote/lib/with-tarball-stream.js:110:55)
npm verb stack     at tryCatcher (/usr/lib/node_modules/npm/node_modules/bluebird/js/release/util.js:16:23)
npm verb stack     at Promise._settlePromiseFromHandler (/usr/lib/node_modules/npm/node_modules/bluebird/js/release/promise.js:512:31)
npm verb stack     at Promise._settlePromise (/usr/lib/node_modules/npm/node_modules/bluebird/js/release/promise.js:569:18)
npm verb stack     at Promise._settlePromise0 (/usr/lib/node_modules/npm/node_modules/bluebird/js/release/promise.js:614:10)
npm verb stack     at Promise._settlePromises (/usr/lib/node_modules/npm/node_modules/bluebird/js/release/promise.js:690:18)
npm verb stack     at _drainQueueStep (/usr/lib/node_modules/npm/node_modules/bluebird/js/release/async.js:138:12)
npm verb stack     at _drainQueue (/usr/lib/node_modules/npm/node_modules/bluebird/js/release/async.js:131:9)
npm verb stack     at Async._drainQueues (/usr/lib/node_modules/npm/node_modules/bluebird/js/release/async.js:147:5)
npm verb stack     at Immediate.Async.drainQueues (/usr/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 /usr/src/app
npm verb Linux 4.13.0-25-generic
npm verb argv "/usr/bin/node" "/usr/bin/npm" "ci" "--verbose"
npm verb node v8.15.0
npm verb npm  v6.7.0
npm ERR! err.code.match is not a function
npm verb exit [ 1, true ]
```

Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
@thundron
Copy link

thundron commented Jun 1, 2019

Any ETA on when this PR could be merged? Hitting this issue as well, not sure about how to reproduce but so far running node 10 and npm 6.7.0 on Debian seems to always do that

@kevivell
Copy link

Any ideas when this will be merged please?

@mhavelka
Copy link

Also voting for merging pls.

@zkat zkat merged commit 92f5e4c into zkat:latest Jun 17, 2019
@parties
Copy link

parties commented Jun 17, 2019

Thank you, @zkat!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants