From f0df62200dcf0f5705f29fef4ce8e969d8b8dc12 Mon Sep 17 00:00:00 2001 From: Patricio Palladino Date: Thu, 9 May 2019 15:28:37 -0300 Subject: [PATCH] Include the unrecognized string in the error message --- src/bytes.ts | 2 +- test/index.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/bytes.ts b/src/bytes.ts index 9149d0e1..ab3c2831 100644 --- a/src/bytes.ts +++ b/src/bytes.ts @@ -76,7 +76,7 @@ export const toBuffer = function(v: any): Buffer { v = Buffer.from(ethjsUtil.padToEven(ethjsUtil.stripHexPrefix(v)), 'hex') } else { throw new Error( - 'Cannot convert string to buffer. toBuffer only supports 0x-prefixed hex strings.', + `Cannot convert string to buffer. toBuffer only supports 0x-prefixed hex strings and this string was given: ${v}`, ) } } else if (typeof v === 'number') { diff --git a/test/index.js b/test/index.js index b9e5bd94..9a558f19 100644 --- a/test/index.js +++ b/test/index.js @@ -507,9 +507,9 @@ describe('toBuffer', function () { }) it('should fail with non 0x-prefixed hex strings', function() { - assert.throws(() => ethUtils.toBuffer('11')) + assert.throws(() => ethUtils.toBuffer('11'), '11') assert.throws(() => ethUtils.toBuffer('')) - assert.throws(() => ethUtils.toBuffer('0xR')) + assert.throws(() => ethUtils.toBuffer('0xR'), '0xR') }) })