From e511c442e682908be1d7c7120eef09f080b94af7 Mon Sep 17 00:00:00 2001 From: Christian Machacek <39452430+machacekch@users.noreply.github.com> Date: Tue, 11 May 2021 00:55:51 +0200 Subject: [PATCH] fix: improve findProgramAddress error when MAX_SEED_LENGTH is exceeded (#17151) --- web3.js/src/publickey.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/web3.js/src/publickey.ts b/web3.js/src/publickey.ts index 66f5945066..4837f545a3 100644 --- a/web3.js/src/publickey.ts +++ b/web3.js/src/publickey.ts @@ -113,7 +113,7 @@ export class PublicKey { let buffer = Buffer.alloc(0); seeds.forEach(function (seed) { if (seed.length > MAX_SEED_LENGTH) { - throw new Error(`Max seed length exceeded`); + throw new TypeError(`Max seed length exceeded`); } buffer = Buffer.concat([buffer, toBuffer(seed)]); }); @@ -148,6 +148,9 @@ export class PublicKey { const seedsWithNonce = seeds.concat(Buffer.from([nonce])); address = await this.createProgramAddress(seedsWithNonce, programId); } catch (err) { + if (err instanceof TypeError) { + throw err; + } nonce--; continue; }