cacache icon indicating copy to clipboard operation
cacache copied to clipboard

[BUG] TypeError: buckets.map is not a function => app crash

Open shentaoy opened this issue 2 years ago • 1 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Current Behavior

NpmCache::getCacheDbItems failed due to TypeError: buckets.map is not a function at readdirOrEmpty.then.buckets (main.js:238:3754) at at Function.reReject (main.js:4453:1407) at cacache_1.default.ls.then.catch.e (main.js:5513:7616) at code: undefined }

Looks like there is error during reading the dir.

function readdirOrEmpty (dir) {
  return fs.readdir(dir).catch((err) => {
    if (err.code === 'ENOENT' || err.code === 'ENOTDIR') {
      return []
    }

    throw err
  })
}

But it's not properly handled here.

  Promise.resolve().then(async () => {
    const buckets = await readdirOrEmpty(indexDir)
    await Promise.all(buckets.map(async (bucket) => {
    ...

Expected Behavior

Promise rejected instead of crash.

Steps To Reproduce

Issue is sporadic.

Environment

  • npm: 6.14.16
  • Node: 8.16.2
  • OS: Linux

shentaoy avatar Jun 08 '22 09:06 shentaoy

@shentaoy Is there a way you can reproduce this error? The only possible way for this error to happen seems to be a case where fs.readdir(dir) returns something other than an array!

MohGanji avatar Aug 12 '22 23:08 MohGanji

Is it possible you're using something like fake-fs to fake the filesystem, e.g. for testing?

jamesarosen avatar Nov 08 '22 20:11 jamesarosen

Can't reproduce

wraithgar avatar May 02 '23 20:05 wraithgar