Skip to content

Commit

Permalink
refactor: Error constructor does not need new
Browse files Browse the repository at this point in the history
  • Loading branch information
erights committed Apr 27, 2023
1 parent 9a3d9b4 commit 9981e56
Show file tree
Hide file tree
Showing 72 changed files with 131 additions and 145 deletions.
6 changes: 3 additions & 3 deletions packages/SwingSet/misc-tools/replay-transcript.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ async function replay(transcriptFile) {
}
syscallResults = {};
if (divergent && !argv.ignoreConcurrentWorkerDivergences) {
throw new Error('Divergent execution between workers');
throw Error('Divergent execution between workers');
}
};

Expand Down Expand Up @@ -566,7 +566,7 @@ async function replay(transcriptFile) {
if (argv.ignoreSnapshotHashDifference) {
console.warn(errorMessage);
} else {
throw new Error(errorMessage);
throw Error(errorMessage);
}
} else {
console.log(
Expand Down Expand Up @@ -720,7 +720,7 @@ async function replay(transcriptFile) {
if (argv.ignoreSnapshotHashDifference) {
console.warn(errorMessage);
} else {
throw new Error(errorMessage);
throw Error(errorMessage);
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/SwingSet/src/devices/bridge/bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ export function buildBridge(outboundCallback) {

function registerInboundCallback(inbound) {
if (inboundCallback) {
throw new Error('inboundCallback already registered');
throw Error('inboundCallback already registered');
}
inboundCallback = inbound;
}

function deliverInbound(...args) {
if (!inboundCallback) {
throw new Error('inboundCallback not yet registered');
throw Error('inboundCallback not yet registered');
}
inboundCallback(...args);
}
Expand Down
4 changes: 1 addition & 3 deletions packages/SwingSet/src/devices/command/device-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ export function buildRootDeviceNode(tools) {

registerInboundCallback((count, bodyString) => {
if (!inboundHandler) {
throw new Error(
`CMD inboundHandler not set before registerInboundHandler`,
);
throw Error(`CMD inboundHandler not set before registerInboundHandler`);
}
try {
const body = JSON.parse(`${bodyString}`);
Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/src/devices/mailbox/device-mailbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function buildRootDeviceNode(tools) {

function inboundCallback(peer, messages, ack) {
if (!deliverInboundMessages) {
throw new Error(
throw Error(
`mailbox.inboundCallback(${peer}) called before handler was registered`,
);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/SwingSet/src/kernel/deviceSlots.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export function makeDeviceSlots(
);
const t = slotToVal.get(deviceID);
if (!(method in t)) {
throw new TypeError(
throw TypeError(
`target[${method}] does not exist, has ${Object.getOwnPropertyNames(
t,
)}`,
Expand All @@ -210,7 +210,7 @@ export function makeDeviceSlots(
const fn = t[method];
const ftype = typeof fn;
if (ftype !== 'function') {
throw new TypeError(
throw TypeError(
`target[${method}] is not a function, typeof is ${ftype}, has ${Object.getOwnPropertyNames(
t,
)}`,
Expand Down
10 changes: 5 additions & 5 deletions packages/SwingSet/src/kernel/kernel.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ export default function buildKernel(

function addImport(forVatID, what) {
if (!started) {
throw new Error('must do kernel.start() before addImport()');
throw Error('must do kernel.start() before addImport()');
// because otherwise we can't get the vatManager
}
insistVatID(forVatID);
Expand All @@ -224,7 +224,7 @@ export default function buildKernel(

function addExport(fromVatID, vatSlot) {
if (!started) {
throw new Error('must do kernel.start() before addExport()');
throw Error('must do kernel.start() before addExport()');
// because otherwise we can't get the vatKeeper
}
return doAddExport(kernelKeeper, fromVatID, vatSlot);
Expand All @@ -237,7 +237,7 @@ export default function buildKernel(
/** @type {import('../types-internal.js').KernelPanic} */
function panic(problem, err = undefined) {
console.error(`##### KERNEL PANIC: ${problem} #####`);
kernelPanic = err || new Error(`kernel panic ${problem}`);
kernelPanic = err || Error(`kernel panic ${problem}`);
}

const { doSend, doSubscribe, doResolve, resolveToError, queueToKref } =
Expand Down Expand Up @@ -1748,7 +1748,7 @@ export default function buildKernel(
throw kernelPanic;
}
if (!started) {
throw new Error('must do kernel.start() before step()');
throw Error('must do kernel.start() before step()');
}
kernelKeeper.startCrank();
try {
Expand Down Expand Up @@ -1782,7 +1782,7 @@ export default function buildKernel(
throw kernelPanic;
}
if (!started) {
throw new Error('must do kernel.start() before run()');
throw Error('must do kernel.start() before run()');
}
let count = 0;
for (;;) {
Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/src/kernel/kernelQueue.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function makeKernelQueueHandler(tools) {
const {
kernelKeeper,
panic = (problem, err) => {
throw err || new Error(`kernel panic ${problem}`);
throw err || Error(`kernel panic ${problem}`);
},
} = tools;

Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/src/kernel/vatTranslator.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function makeTranslateKernelDeliveryToVatDelivery(vatID, kernelKeeper) {
// TODO unimplemented
// NOTE: When adding redirection / forwarding, we must handle any
// pipelined messages pending in the inbound queue
throw new Error('not implemented yet');
throw Error('not implemented yet');
} else {
throw Fail`unknown kernelPromise state '${kp.state}'`;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/test/vat-direct.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export default function setup(syscall, _state, _helpers, vatPowers) {
}

default:
throw new Error(`unrecognized method ${method}`);
throw Error(`unrecognized method ${method}`);
}
} catch (err) {
resolutions = promiseRejection(result, err);
Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/test/vat-exomessages.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function buildRootObject(_vatPowers, vatParameters) {
} else if (mode === 'presence') {
return other;
} else if (mode === 'reject') {
throw new Error('gratuitous error');
throw Error('gratuitous error');
}
return undefined;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/tools/vat.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ async function main() {
}
const command = argv.shift();
if (command !== 'run' && command !== 'shell') {
throw new Error(`use 'vat run' or 'vat shell', not 'vat ${command}'`);
throw Error(`use 'vat run' or 'vat shell', not 'vat ${command}'`);
}
const basedir =
argv[0] === '--' || argv[0] === undefined ? '.' : argv.shift();
Expand Down
20 changes: 10 additions & 10 deletions packages/access-token/src/json-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function makeStorageInMemory() {
*/
function has(key) {
if (`${key}` !== key) {
throw new Error(`non-string key ${key}`);
throw Error(`non-string key ${key}`);
}
return state.has(key);
}
Expand All @@ -74,10 +74,10 @@ function makeStorageInMemory() {
*/
function* getKeys(start, end) {
if (`${start}` !== start) {
throw new Error(`non-string start ${start}`);
throw Error(`non-string start ${start}`);
}
if (`${end}` !== end) {
throw new Error(`non-string end ${end}`);
throw Error(`non-string end ${end}`);
}

const keys = Array.from(state.keys()).sort();
Expand All @@ -100,7 +100,7 @@ function makeStorageInMemory() {
*/
function get(key) {
if (`${key}` !== key) {
throw new Error(`non-string key ${key}`);
throw Error(`non-string key ${key}`);
}
return state.get(key);
}
Expand All @@ -116,10 +116,10 @@ function makeStorageInMemory() {
*/
function set(key, value) {
if (`${key}` !== key) {
throw new Error(`non-string key ${key}`);
throw Error(`non-string key ${key}`);
}
if (`${value}` !== value) {
throw new Error(`non-string value ${value}`);
throw Error(`non-string value ${value}`);
}
state.set(key, value);
}
Expand All @@ -134,7 +134,7 @@ function makeStorageInMemory() {
*/
function del(key) {
if (`${key}` !== key) {
throw new Error(`non-string key ${key}`);
throw Error(`non-string key ${key}`);
}
state.delete(key);
}
Expand Down Expand Up @@ -244,7 +244,7 @@ function makeJSONStore(dirPath, forceReset = false) {
*/
export function initJSONStore(dirPath) {
if (dirPath !== null && dirPath !== undefined && `${dirPath}` !== dirPath) {
throw new Error('dirPath must be a string or nullish');
throw Error('dirPath must be a string or nullish');
}
return makeJSONStore(dirPath, true);
}
Expand All @@ -268,7 +268,7 @@ export function initJSONStore(dirPath) {
*/
export function openJSONStore(dirPath) {
if (`${dirPath}` !== dirPath) {
throw new Error('dirPath must be a string');
throw Error('dirPath must be a string');
}
return makeJSONStore(dirPath, false);
}
Expand Down Expand Up @@ -324,7 +324,7 @@ export function setAllState(storage, stuff) {
*/
export function isJSONStore(dirPath) {
if (`${dirPath}` !== dirPath) {
throw new Error('dirPath must be a string');
throw Error('dirPath must be a string');
}
if (fs.existsSync(dirPath)) {
const storeFile = path.resolve(dirPath, DATA_FILE);
Expand Down
6 changes: 3 additions & 3 deletions packages/agoric-cli/src/commands/oracle.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const makeOracleCommand = logger => {
`
WALLET=my-wallet
export AGORIC_NET=ollinet
# provision wallet if necessary
agd keys add $WALLET
# provision with faucet, e.g.
Expand All @@ -35,7 +35,7 @@ export const makeOracleCommand = logger => {
# prepare an offer to send
# (offerId is optional but best to specify as each must be higher than the last and the default value is a huge number)
agops oracle accept --offerId 12 > offer-12.json
# sign and send
agoric wallet send --from $WALLET --offer offer-12.json
`,
Expand All @@ -49,7 +49,7 @@ export const makeOracleCommand = logger => {
const instance = utils.agoricNames.instance[name];
if (!instance) {
logger.debug('known instances:', utils.agoricNames.instance);
throw new Error(`Unknown instance ${name}`);
throw Error(`Unknown instance ${name}`);
}
return instance;
};
Expand Down
6 changes: 3 additions & 3 deletions packages/agoric-cli/src/commands/psm.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const makePsmCommand = logger => {
`
WALLET=my-wallet
export AGORIC_NET=ollinet
# provision wallet if necessary
agd keys add $WALLET
# provision with faucet, e.g.
Expand All @@ -52,7 +52,7 @@ export const makePsmCommand = logger => {
# prepare an offer to send
# (offerId is optional but best to specify as each must be higher than the last and the default value is a huge number)
agops psm swap --wantMinted 6 --feePct 0.01 --offerId 12 > offer-12.json
# watch for results in one terminal
agoric wallet watch --from $WALLET
Expand All @@ -70,7 +70,7 @@ export const makePsmCommand = logger => {
const instance = utils.agoricNames.instance[name];
if (!instance) {
logger.debug('known instances:', utils.agoricNames.instance);
throw new Error(`Unknown instance ${name}`);
throw Error(`Unknown instance ${name}`);
}
return instance;
};
Expand Down
4 changes: 1 addition & 3 deletions packages/agoric-cli/src/cosmos.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ export default async function cosmosMain(progname, rawArgs, powers, opts) {
)
.then(code => {
if (code !== 0) {
throw new Error(
`Cosmos client helper build failed with code ${code}`,
);
throw Error(`Cosmos client helper build failed with code ${code}`);
}
return pspawn(cosmosHelper, args, hopts);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/agoric-cli/src/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ export { bootPlugin } from ${JSON.stringify(absPath)};
read,
url.pathToFileURL(moduleFile),
).catch(cause => {
throw new Error(
throw Error(
`Expected a package.json beside deploy script ${moduleFile}, ${cause}`,
{ cause },
);
Expand Down
4 changes: 2 additions & 2 deletions packages/agoric-cli/src/json-http-client-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ export const makeJsonHttpClient = ({ http }) => {
const responseBytes = Buffer.concat(chunks);
const responseText = textDecoder.decode(responseBytes);
if (response.statusCode !== 200) {
throw new Error(`${responseText}`);
throw Error(`${responseText}`);
}
// May throw: becomes rejection below.
const responseBody = JSON.parse(responseText);
resolve(responseBody);
})().catch(cause => {
reject(
new Error(`JSON HTTP RPC failed with error: ${cause.message}`, {
Error(`JSON HTTP RPC failed with error: ${cause.message}`, {
cause,
}),
);
Expand Down
2 changes: 1 addition & 1 deletion packages/agoric-cli/src/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const parseLocatedJson = (source, location) => {
return JSON.parse(source);
} catch (error) {
if (error instanceof SyntaxError) {
throw new SyntaxError(`Cannot parse JSON from ${location}, ${error}`);
throw SyntaxError(`Cannot parse JSON from ${location}, ${error}`);
}
throw error;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/agoric-cli/src/lib/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import '@agoric/ertp/src/types-ambient.js';
export const Natural = str => {
const b = BigInt(str);
if (b < 0) {
throw new RangeError(`${b} is negative`);
throw RangeError(`${b} is negative`);
}
return b;
};
Expand Down Expand Up @@ -93,7 +93,7 @@ export const asBoardRemote = x => {

/**
* Summarize the balances array as user-facing informative tuples
* @param {import('@agoric/smart-wallet/src/smartWallet').CurrentWalletRecord['purses']} purses
* @param {AssetDescriptor[]} assets
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/agoric-cli/src/lib/rpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ export const makeRpcUtils = async ({ fetch }, config = networkConfig) => {
vstorage,
};
} catch (err) {
throw new Error(`RPC failure (${config.rpcAddrs}): ${err.message}`);
throw Error(`RPC failure (${config.rpcAddrs}): ${err.message}`);
}
};
/** @typedef {Awaited<ReturnType<typeof makeRpcUtils>>} RpcUtils */
2 changes: 1 addition & 1 deletion packages/agoric-cli/src/lib/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export const makeWalletUtils = async (
* @returns {(a: string) => Amount<'nat'>}
*/
export const makeParseAmount =
(agoricNames, makeError = msg => new RangeError(msg)) =>
(agoricNames, makeError = msg => RangeError(msg)) =>
opt => {
assert.typeof(opt, 'string', 'parseAmount expected string');
const m = opt.match(/^(?<value>[\d_]+(\.[\d_]+)?)(?<brand>[A-Z]\w*?)$/);
Expand Down
Loading

0 comments on commit 9981e56

Please sign in to comment.