Skip to content

Commit

Permalink
refactor: standardize error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
guanzo committed Sep 21, 2023
1 parent d62d015 commit d5d1ee9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/utils/car-block-getter.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@ export class CarBlockGetter {
const { value, done } = await promiseTimeout(
this.carItr.next(),
this.getBlockTimeout,
new TimeoutError(`get block ${cid} timed out`)
new TimeoutError(`get ${cid}: timed out`)
)

if (!value && done) {
throw new VerificationError('CAR file has no more blocks.')
throw new VerificationError(`get ${cid}: CAR file has no more blocks`)
}

const { cid: blockCid, bytes } = value
await verifyBlock(blockCid, bytes)

if (!cid.equals(blockCid)) {
throw new VerificationError(
`received block with cid ${blockCid}, expected ${cid}`
`get ${cid}: received ${blockCid} instead`
)
}

Expand Down
4 changes: 2 additions & 2 deletions test/car.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ describe('CAR Verification', () => {
},
{
name: 'VerificationError',
message: 'CAR file has no more blocks.'
message: 'get bafybeidhkumeonuwkebh2i4fc7o7lguehauradvlk57gzake6ggjsy372a: CAR file has no more blocks'
}
)
})
Expand Down Expand Up @@ -155,7 +155,7 @@ describe('CAR Verification', () => {
{
name: 'VerificationError',
message:
'received block with cid bafybeidhkumeonuwkebh2i4fc7o7lguehauradvlk57gzake6ggjsy372a, expected bafybeigeqgfwhivuuxgmuvcrrwvs4j3yfzgljssvnuqzokm6uby4fpmwsa'
'get bafybeigeqgfwhivuuxgmuvcrrwvs4j3yfzgljssvnuqzokm6uby4fpmwsa: received bafybeidhkumeonuwkebh2i4fc7o7lguehauradvlk57gzake6ggjsy372a instead'
}
)
})
Expand Down

0 comments on commit d5d1ee9

Please sign in to comment.