From d5d1ee94e7a39df399166c0acf7d5ca02c278979 Mon Sep 17 00:00:00 2001 From: Eric Guan Date: Thu, 21 Sep 2023 16:02:43 -0700 Subject: [PATCH] refactor: standardize error messages --- src/utils/car-block-getter.js | 6 +++--- test/car.spec.js | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/utils/car-block-getter.js b/src/utils/car-block-getter.js index c73236a..8155625 100644 --- a/src/utils/car-block-getter.js +++ b/src/utils/car-block-getter.js @@ -34,11 +34,11 @@ 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 @@ -46,7 +46,7 @@ export class CarBlockGetter { if (!cid.equals(blockCid)) { throw new VerificationError( - `received block with cid ${blockCid}, expected ${cid}` + `get ${cid}: received ${blockCid} instead` ) } diff --git a/test/car.spec.js b/test/car.spec.js index 2c83ef3..15d981f 100644 --- a/test/car.spec.js +++ b/test/car.spec.js @@ -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' } ) }) @@ -155,7 +155,7 @@ describe('CAR Verification', () => { { name: 'VerificationError', message: - 'received block with cid bafybeidhkumeonuwkebh2i4fc7o7lguehauradvlk57gzake6ggjsy372a, expected bafybeigeqgfwhivuuxgmuvcrrwvs4j3yfzgljssvnuqzokm6uby4fpmwsa' + 'get bafybeigeqgfwhivuuxgmuvcrrwvs4j3yfzgljssvnuqzokm6uby4fpmwsa: received bafybeidhkumeonuwkebh2i4fc7o7lguehauradvlk57gzake6ggjsy372a instead' } ) })