Skip to content

Commit

Permalink
fixup! restore "new" for non-builtin *Errors
Browse files Browse the repository at this point in the history
  • Loading branch information
erights committed Sep 4, 2024
1 parent ec849ee commit 7f70798
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 10 deletions.
4 changes: 3 additions & 1 deletion packages/agoric-cli/src/commands/auction.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 9 additions & 3 deletions packages/agoric-cli/src/commands/gov.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
}
};

Expand Down Expand Up @@ -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
Expand All @@ -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 ...',
Expand Down
20 changes: 16 additions & 4 deletions packages/agoric-cli/src/commands/inter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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?`,
);
}
};

Expand All @@ -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);
}
};

Expand Down Expand Up @@ -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;
};
Expand Down Expand Up @@ -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 };
Expand Down
4 changes: 3 additions & 1 deletion packages/agoric-cli/src/commands/test-upgrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};

Expand Down
4 changes: 3 additions & 1 deletion packages/agoric-cli/test/inter-cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit 7f70798

Please sign in to comment.