cacache
cacache copied to clipboard
[BUG] TypeError: buckets.map is not a function => app crash
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
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 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!
Is it possible you're using something like fake-fs
to fake the filesystem, e.g. for testing?
Can't reproduce