diff --git a/lib/cache/entry.js b/lib/cache/entry.js index 4514109..bfcfacb 100644 --- a/lib/cache/entry.js +++ b/lib/cache/entry.js @@ -274,6 +274,8 @@ class CacheEntry { const cacheWritePromise = new Promise((resolve, reject) => { cacheWriteResolve = resolve cacheWriteReject = reject + }).catch((err) => { + body.emit('error', err) }) body = new CachingMinipassPipeline({ events: ['integrity', 'size'] }, new MinipassFlush({ diff --git a/test/inaccessible-cache.js b/test/inaccessible-cache.js new file mode 100644 index 0000000..f749e92 --- /dev/null +++ b/test/inaccessible-cache.js @@ -0,0 +1,24 @@ +const nock = require('nock') +const t = require('tap') +const path = require('path') + +const fetch = require('../') +nock.disableNetConnect() + +t.beforeEach(() => nock.cleanAll()) +t.test('catches error for inaccessible cache', async t => { + // a file for the cache which wont work + const cache = t.testdir({ + file: '', + }) + const req = nock('http://localhost') + .get('/foo') + .reply(() => [200, Buffer.from('text')]) + + const res = await fetch('http://localhost/foo', { + cachePath: path.resolve(cache, 'file'), + }) + + await t.rejects(res.text(), { code: 'ENOTDIR' }) + t.ok(req.isDone()) +})