From 7f70798f2ef45b3b9a2a4f39d35915859879eac4 Mon Sep 17 00:00:00 2001 From: "Mark S. Miller" Date: Wed, 4 Sep 2024 14:11:55 -0700 Subject: [PATCH] fixup! restore "new" for non-builtin *Errors --- packages/agoric-cli/src/commands/auction.js | 4 +++- packages/agoric-cli/src/commands/gov.js | 12 ++++++++--- packages/agoric-cli/src/commands/inter.js | 20 +++++++++++++++---- .../agoric-cli/src/commands/test-upgrade.js | 4 +++- packages/agoric-cli/test/inter-cli.test.js | 4 +++- 5 files changed, 34 insertions(+), 10 deletions(-) diff --git a/packages/agoric-cli/src/commands/auction.js b/packages/agoric-cli/src/commands/auction.js index 3d4047a6713..99ffd43355c 100644 --- a/packages/agoric-cli/src/commands/auction.js +++ b/packages/agoric-cli/src/commands/auction.js @@ -130,7 +130,9 @@ export const makeAuctionCommand = ( }; if (Object.keys(params).length === 0) { - throw InvalidArgumentError(`no parameters given`); + // InvalidArgumentError is a class constructor, and so + // must be invoked with `new`. + throw new InvalidArgumentError(`no parameters given`); } const instance = agoricNames.instance.auctioneer; diff --git a/packages/agoric-cli/src/commands/gov.js b/packages/agoric-cli/src/commands/gov.js index 8631f0459aa..8a4b46d49e5 100644 --- a/packages/agoric-cli/src/commands/gov.js +++ b/packages/agoric-cli/src/commands/gov.js @@ -73,7 +73,9 @@ export const makeGovCommand = (_logger, io = {}) => { const done = found.filter(it => it.instanceName === instanceName); if (done.length > 0) { console.warn(`invitation to ${instanceName} already accepted`, done); - throw CommanderError(1, 'EALREADY', `already accepted`); + // CommanderError is a class constructor, and so + // must be invoked with `new`. + throw new CommanderError(1, 'EALREADY', `already accepted`); } }; @@ -330,7 +332,9 @@ export const makeGovCommand = (_logger, io = {}) => { const info = await readLatestHead( `published.committees.${opts.pathname}.latestQuestion`, ).catch(err => { - throw CommanderError(1, 'VSTORAGE_FAILURE', err.message); + // CommanderError is a class constructor, and so + // must be invoked with `new`. + throw new CommanderError(1, 'VSTORAGE_FAILURE', err.message); }); // XXX runtime shape-check @@ -346,7 +350,9 @@ export const makeGovCommand = (_logger, io = {}) => { const votingRight = cont.find(it => it.instanceName === opts.instance); if (!votingRight) { console.debug('continuing ids', cont, 'for', current); - throw CommanderError( + // CommanderError is a class constructor, and so + // must be invoked with `new`. + throw new CommanderError( 1, 'NO_INVITATION', 'first, try: agops ec committee ...', diff --git a/packages/agoric-cli/src/commands/inter.js b/packages/agoric-cli/src/commands/inter.js index 9aea7adce4a..702b2ae0f48 100644 --- a/packages/agoric-cli/src/commands/inter.js +++ b/packages/agoric-cli/src/commands/inter.js @@ -218,7 +218,11 @@ export const makeInterCommand = ( try { return rawExec(file, args, ...opts); } catch (err) { - throw InvalidArgumentError(`${err.message}: is ${file} in your $PATH?`); + // InvalidArgumentError is a class constructor, and so + // must be invoked with `new`. + throw new InvalidArgumentError( + `${err.message}: is ${file} in your $PATH?`, + ); } }; @@ -237,7 +241,9 @@ export const makeInterCommand = ( const networkConfig = await getNetworkConfig(env); return makeWalletUtils({ fetch, execFileSync, delay }, networkConfig); } catch (err) { - throw CommanderError(1, 'RPC_FAIL', err.message); + // CommanderError is a class constructor, and so + // must be invoked with `new`. + throw new CommanderError(1, 'RPC_FAIL', err.message); } }; @@ -429,7 +435,9 @@ inter auction status const parsePercent = v => { const p = Number(v); if (!(p >= -100 && p <= 100)) { - throw InvalidArgumentError('must be between -100 and 100'); + // InvalidArgumentError is a class constructor, and so + // must be invoked with `new`. + throw new InvalidArgumentError('must be between -100 and 100'); } return p / 100; }; @@ -496,7 +504,11 @@ inter auction status const current = await getCurrent(from, { readLatestHead }); const liveIds = current.liveOffers.map(([i, _s]) => i); if (!liveIds.includes(id)) { - throw InvalidArgumentError(`${id} not in live offer ids: ${liveIds}`); + // InvalidArgumentError is a class constructor, and so + // must be invoked with `new`. + throw new InvalidArgumentError( + `${id} not in live offer ids: ${liveIds}`, + ); } const io = { ...networkConfig, execFileSync, delay, stdout }; diff --git a/packages/agoric-cli/src/commands/test-upgrade.js b/packages/agoric-cli/src/commands/test-upgrade.js index b309ba70416..20223ee7bc5 100644 --- a/packages/agoric-cli/src/commands/test-upgrade.js +++ b/packages/agoric-cli/src/commands/test-upgrade.js @@ -41,7 +41,9 @@ export const makeTestCommand = ( const networkConfig = await getNetworkConfig(env); return makeWalletUtils({ fetch, execFileSync, delay }, networkConfig); } catch (err) { - throw CommanderError(1, 'RPC_FAIL', err.message); + // CommanderError is a class constructor, and so + // must be invoked with `new`. + throw new CommanderError(1, 'RPC_FAIL', err.message); } }; diff --git a/packages/agoric-cli/test/inter-cli.test.js b/packages/agoric-cli/test/inter-cli.test.js index 772d769f29f..5d7bb758626 100644 --- a/packages/agoric-cli/test/inter-cli.test.js +++ b/packages/agoric-cli/test/inter-cli.test.js @@ -366,7 +366,9 @@ const usageTest = (words, blurb = 'Command usage:') => { program.addCommand(cmd); for (const c of subCommands(program)) { c.exitOverride(() => { - throw CommanderError(1, 'usage', ''); + // CommanderError is a class constructor, and so + // must be invoked with `new`. + throw new CommanderError(1, 'usage', ''); }); } cmd.configureOutput({