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

Commit fa918f5

Browse files
committed
fix(content): rethrow aggregate errors as ENOENT
1 parent 5d09c81 commit fa918f5

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lib/content/read.js

+10
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,16 @@ function pickContentSri (cache, integrity) {
9595
return BB.any(sri[sri.pickAlgorithm()].map(meta => {
9696
return pickContentSri(cache, meta)
9797
}))
98+
.catch(err => {
99+
if ([].some.call(err, e => e.code === 'ENOENT')) {
100+
throw Object.assign(
101+
new Error('No matching content found for ' + sri.toString()),
102+
{code: 'ENOENT'}
103+
)
104+
} else {
105+
throw err[0]
106+
}
107+
})
98108
}
99109
}
100110

test/content.read.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,18 @@ test('hasContent: returns { sri, size } when a cache file exists', function (t)
141141
}))
142142
fixture.create(CACHE)
143143
return BB.join(
144-
read.hasContent(CACHE, 'sha1-deadbeef').then(content => {
144+
read.hasContent(CACHE, 'sha1-deadbeef')
145+
.then(content => {
145146
t.ok(content.sri, 'returned sri for this content')
146147
t.equal(content.size, 0, 'returned the right size for this content')
147148
}),
148-
read.hasContent(CACHE, 'sha1-not-there').then(content => {
149+
read.hasContent(CACHE, 'sha1-not-there')
150+
.then(content => {
149151
t.equal(content, false, 'returned false for missing content')
152+
}),
153+
read.hasContent(CACHE, 'sha1-not-here sha1-also-not-here')
154+
.then(content => {
155+
t.equal(content, false, 'multi-content hash failures work ok')
150156
})
151157
)
152158
})

0 commit comments

Comments
 (0)