Skip to content

Commit

Permalink
fix(content): rethrow aggregate errors as ENOENT
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Feb 16, 2018
1 parent 5d09c81 commit fa918f5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
10 changes: 10 additions & 0 deletions lib/content/read.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@ function pickContentSri (cache, integrity) {
return BB.any(sri[sri.pickAlgorithm()].map(meta => {
return pickContentSri(cache, meta)
}))
.catch(err => {
if ([].some.call(err, e => e.code === 'ENOENT')) {
throw Object.assign(
new Error('No matching content found for ' + sri.toString()),
{code: 'ENOENT'}
)
} else {
throw err[0]
}
})
}
}

Expand Down
10 changes: 8 additions & 2 deletions test/content.read.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,18 @@ test('hasContent: returns { sri, size } when a cache file exists', function (t)
}))
fixture.create(CACHE)
return BB.join(
read.hasContent(CACHE, 'sha1-deadbeef').then(content => {
read.hasContent(CACHE, 'sha1-deadbeef')
.then(content => {
t.ok(content.sri, 'returned sri for this content')
t.equal(content.size, 0, 'returned the right size for this content')
}),
read.hasContent(CACHE, 'sha1-not-there').then(content => {
read.hasContent(CACHE, 'sha1-not-there')
.then(content => {
t.equal(content, false, 'returned false for missing content')
}),
read.hasContent(CACHE, 'sha1-not-here sha1-also-not-here')
.then(content => {
t.equal(content, false, 'multi-content hash failures work ok')
})
)
})
Expand Down

0 comments on commit fa918f5

Please sign in to comment.