diff --git a/packages/cli/demo/cat.js b/packages/cli/demo/cat.js index 4492f7068b..9c2928f9e7 100644 --- a/packages/cli/demo/cat.js +++ b/packages/cli/demo/cat.js @@ -824,9 +824,7 @@ const render = value => { return $value; } default: { - throw new Error( - 'Unreachable if programmed to account for all pass-styles', - ); + throw Error('Unreachable if programmed to account for all pass-styles'); } } }; @@ -908,7 +906,7 @@ const evalComponent = ($parent, powers, { dismissEval, showValue }) => { const id = target.getAttribute('id'); const $endowment = $endowments.get(id); if ($endowment === undefined) { - throw new Error(`Endowment does not exist for id ${id}`); + throw Error(`Endowment does not exist for id ${id}`); } $endowments.delete(id); $endowment.remove(); diff --git a/packages/cli/src/commands/eval.js b/packages/cli/src/commands/eval.js index eb198edb38..5ee244c1e4 100644 --- a/packages/cli/src/commands/eval.js +++ b/packages/cli/src/commands/eval.js @@ -19,7 +19,7 @@ export const evalCommand = async ({ return [name, name]; } if (pair.length > 2) { - throw new Error( + throw Error( `Specify either a name endowmentName:pet-name, got: ${JSON.stringify( name, )}`, diff --git a/packages/cli/src/pet-name.js b/packages/cli/src/pet-name.js index f4c91ebddc..7005734d53 100644 --- a/packages/cli/src/pet-name.js +++ b/packages/cli/src/pet-name.js @@ -13,9 +13,7 @@ export const parsePetNamePath = petNamePath => { const petNames = petNamePath.split('.'); for (const petName of petNames) { if (petName === '') { - throw new Error( - `Pet name path ${q(petNamePath)} contains an empty segment.`, - ); + throw Error(`Pet name path ${q(petNamePath)} contains an empty segment.`); } } return petNames; diff --git a/packages/compartment-mapper/src/bundle.js b/packages/compartment-mapper/src/bundle.js index fe63135f1b..e1fcc78a28 100644 --- a/packages/compartment-mapper/src/bundle.js +++ b/packages/compartment-mapper/src/bundle.js @@ -358,7 +358,7 @@ export const makeBundle = async (readPowers, moduleLocation, options) => { } const module = modulesByKey[key]; if (module === undefined) { - throw new Error( + throw Error( `Unable to locate module for key ${q(key)} import specifier ${q( importSpecifier, )} in ${q(module.moduleSpecifier)} of compartment ${q( diff --git a/packages/compartment-mapper/src/node-modules.js b/packages/compartment-mapper/src/node-modules.js index a3f41ace75..e4dc546557 100644 --- a/packages/compartment-mapper/src/node-modules.js +++ b/packages/compartment-mapper/src/node-modules.js @@ -691,7 +691,7 @@ const translateGraph = ( /* c8 ignore next */ if (policy && !packagePolicy) { // this should never happen - throw new TypeError('Unexpectedly falsy package policy'); + throw TypeError('Unexpectedly falsy package policy'); } /** diff --git a/packages/compartment-mapper/src/parse-cjs-shared-export-wrapper.js b/packages/compartment-mapper/src/parse-cjs-shared-export-wrapper.js index c34f4fa3d9..fcce4f72fe 100644 --- a/packages/compartment-mapper/src/parse-cjs-shared-export-wrapper.js +++ b/packages/compartment-mapper/src/parse-cjs-shared-export-wrapper.js @@ -158,7 +158,7 @@ export const wrap = ({ namespace = compartment.importNow(importSpecifier); } else { const invalidProps = findInvalidReadNowPowersProps(readPowers).sort(); - throw new Error( + throw Error( `Synchronous readPowers required for dynamic import of ${assert.quote(importSpecifier)}; missing or invalid prop(s): ${invalidProps.join(', ')}`, ); } diff --git a/packages/compartment-mapper/test/custom-parser.test.js b/packages/compartment-mapper/test/custom-parser.test.js index 65364ca20d..637cdfd207 100644 --- a/packages/compartment-mapper/test/custom-parser.test.js +++ b/packages/compartment-mapper/test/custom-parser.test.js @@ -103,7 +103,7 @@ test('a custom parser may implement policy enforcement (allowed)', async t => { compartmentDescriptor.policy.options && compartmentDescriptor.policy.options.markdown !== true) ) { - throw new Error(`Markdown parsing not allowed for ${q(specifier)}`); + throw Error(`Markdown parsing not allowed for ${q(specifier)}`); } return { @@ -173,7 +173,7 @@ test('a custom parser may implement policy enforcement (disallowed)', async t => compartmentDescriptor.policy.options && compartmentDescriptor.policy.options.markdown !== true) ) { - throw new Error(`Markdown parsing not allowed for ${q(specifier)}`); + throw Error(`Markdown parsing not allowed for ${q(specifier)}`); } return { diff --git a/packages/compartment-mapper/test/fixtures-esm-imports-cjs-define/0.mjs b/packages/compartment-mapper/test/fixtures-esm-imports-cjs-define/0.mjs index 682fc4bd44..6cf3fec9f2 100644 --- a/packages/compartment-mapper/test/fixtures-esm-imports-cjs-define/0.mjs +++ b/packages/compartment-mapper/test/fixtures-esm-imports-cjs-define/0.mjs @@ -1,4 +1,4 @@ import { meaning } from './1.cjs'; if (meaning !== 42) { - throw new Error('Fail'); + throw Error('Fail'); } diff --git a/packages/compartment-mapper/test/scaffold.js b/packages/compartment-mapper/test/scaffold.js index 00ee4ea127..7cfba26301 100644 --- a/packages/compartment-mapper/test/scaffold.js +++ b/packages/compartment-mapper/test/scaffold.js @@ -477,7 +477,7 @@ export function scaffold( // in a way that is difficult to generalize since not all test paths // reach here. if (sourceMaps.size !== 0) { - throw new Error( + throw Error( 'The bundler and importer should agree on source map count', ); } diff --git a/packages/compartment-mapper/test/search.test.js b/packages/compartment-mapper/test/search.test.js index 3730a579ba..4cf1f9ed96 100644 --- a/packages/compartment-mapper/test/search.test.js +++ b/packages/compartment-mapper/test/search.test.js @@ -6,7 +6,7 @@ const makeFakeReadPowers = files => { async read(location) { const bytes = files[location]; if (bytes === undefined) { - throw new Error(`File not found: ${location}`); + throw Error(`File not found: ${location}`); } return bytes; }, diff --git a/packages/daemon/index.js b/packages/daemon/index.js index f6adadb885..9517138151 100644 --- a/packages/daemon/index.js +++ b/packages/daemon/index.js @@ -27,7 +27,7 @@ const removePath = async removalPath => { .rm(removalPath, { recursive: true, force: true }) .catch(cause => { /** @type {object} */ - const error = new Error(cause.message, { cause }); + const error = Error(cause.message, { cause }); error.code = cause.code; throw error; }); @@ -129,7 +129,7 @@ export const start = async (config = defaultConfig) => { 'message' in message && typeof message.message === 'string' ) { - reject(new Error(message.message)); + reject(Error(message.message)); } } }); diff --git a/packages/daemon/src/client.js b/packages/daemon/src/client.js index 5a6c916383..c45c94db80 100644 --- a/packages/daemon/src/client.js +++ b/packages/daemon/src/client.js @@ -18,9 +18,7 @@ export const makeEndoClient = async (name, sockPath, cancelled, bootstrap) => { conn.on('error', (/** @type {any} */ error) => { if (error.code === 'ENOENT') { reject( - new Error( - `Cannot connect to Endo. Is Endo running? ${error.message}`, - ), + Error(`Cannot connect to Endo. Is Endo running? ${error.message}`), ); } else { reject(error); diff --git a/packages/daemon/src/context.js b/packages/daemon/src/context.js index c6c75c4710..480e17381e 100644 --- a/packages/daemon/src/context.js +++ b/packages/daemon/src/context.js @@ -28,7 +28,7 @@ export const makeContextMaker = ({ controllerForId, provideController }) => { const cancel = (reason, prefix = '*') => { if (done) return disposed; done = true; - rejectCancelled(reason || harden(new Error('Cancelled'))); + rejectCancelled(reason || harden(Error('Cancelled'))); console.log(`${prefix} ${id}`); diff --git a/packages/daemon/src/daemon-node-powers.js b/packages/daemon/src/daemon-node-powers.js index d9b609c3bf..c3cee1929c 100644 --- a/packages/daemon/src/daemon-node-powers.js +++ b/packages/daemon/src/daemon-node-powers.js @@ -386,7 +386,7 @@ export const makeDaemonicPersistencePowers = ( const makeFormulaPath = formulaNumber => { const { statePath } = config; if (formulaNumber.length < 3) { - throw new TypeError(`Invalid formula number ${q(formulaNumber)}`); + throw TypeError(`Invalid formula number ${q(formulaNumber)}`); } const head = formulaNumber.slice(0, 2); const tail = formulaNumber.slice(2); @@ -403,13 +403,13 @@ export const makeDaemonicPersistencePowers = ( const { file: formulaPath } = makeFormulaPath(formulaNumber); const formulaText = await filePowers.maybeReadFileText(formulaPath); if (formulaText === undefined) { - throw new ReferenceError(`No reference exists at path ${formulaPath}`); + throw ReferenceError(`No reference exists at path ${formulaPath}`); } const formula = (() => { try { return JSON.parse(formulaText); } catch (error) { - throw new TypeError( + throw TypeError( `Corrupt description for reference in file ${formulaPath}: ${error.message}`, ); } diff --git a/packages/daemon/src/daemon-node.js b/packages/daemon/src/daemon-node.js index 4c84c5502e..4aaf1077de 100644 --- a/packages/daemon/src/daemon-node.js +++ b/packages/daemon/src/daemon-node.js @@ -27,7 +27,7 @@ import { /** @import { Config, Builtins } from './types.js' */ if (process.argv.length < 5) { - throw new Error( + throw Error( `daemon.js requires arguments [sockPath] [statePath] [ephemeralStatePath] [cachePath], got ${process.argv.join( ', ', )}`, @@ -144,11 +144,11 @@ const main = async () => { // Wait for services to end normally await servicesStopped; - cancel(new Error('Terminated normally')); - cancelGracePeriod(new Error('Terminated normally')); + cancel(Error('Terminated normally')); + cancelGracePeriod(Error('Terminated normally')); }; -process.once('SIGINT', () => cancel(new Error('SIGINT'))); +process.once('SIGINT', () => cancel(Error('SIGINT'))); // @ts-ignore Yes, we can assign to exitCode, typedoc. process.exitCode = 1; diff --git a/packages/daemon/src/daemon.js b/packages/daemon/src/daemon.js index 475ab5e696..ccd3346f3a 100644 --- a/packages/daemon/src/daemon.js +++ b/packages/daemon/src/daemon.js @@ -284,7 +284,7 @@ const makeDaemonCore = async ( provide: async requestedId => { const { node } = parseId(requestedId); if (node !== localNodeId) { - throw new Error( + throw Error( `Gateway can only provide local values. Got request for node ${q( node, )}`, @@ -347,7 +347,7 @@ const makeDaemonCore = async ( const gracefulCancel = async () => { E.sendOnly(workerDaemonFacet).terminate(); const cancelWorkerGracePeriod = () => { - throw new Error('Exited gracefully before grace period elapsed'); + throw Error('Exited gracefully before grace period elapsed'); }; const workerGracePeriodCancelled = Promise.race([ gracePeriodElapsed, @@ -355,7 +355,7 @@ const makeDaemonCore = async ( ]).then(cancelWorkerGracePeriod, cancelWorkerGracePeriod); await delay(gracePeriodMs, workerGracePeriodCancelled) .then(() => { - throw new Error( + throw Error( `Worker termination grace period ${gracePeriodMs}ms elapsed`, ); }) @@ -597,7 +597,7 @@ const makeDaemonCore = async ( const endoBootstrap = makeExo('Endo', EndoInterface, { ping: async () => 'pong', terminate: async () => { - cancel(new Error('Termination requested')); + cancel(Error('Termination requested')); }, host: () => provide(hostId, 'host'), leastAuthority: () => provide(leastAuthorityId, 'guest'), @@ -629,7 +629,7 @@ const makeDaemonCore = async ( makeLoopbackNetwork(Promise.resolve(localGateway)), 'least-authority': () => { const disallowedFn = async () => { - throw new Error('not allowed'); + throw Error('not allowed'); }; return /** @type {FarRef} */ ( /** @type {unknown} */ ( @@ -720,7 +720,7 @@ const makeDaemonCore = async ( } return value; } else { - throw new TypeError(`Invalid formula: ${q(formula)}`); + throw TypeError(`Invalid formula: ${q(formula)}`); } }; @@ -816,12 +816,12 @@ const makeDaemonCore = async ( */ const getPeerIdForNodeIdentifier = async nodeId => { if (nodeId === localNodeId) { - throw new Error(`Cannot get peer formula identifier for self`); + throw Error(`Cannot get peer formula identifier for self`); } const knownPeers = await provide(knownPeersId, 'pet-store'); const peerId = knownPeers.identifyLocal(nodeId); if (peerId === undefined) { - throw new Error(`No peer found for node identifier ${q(nodeId)}.`); + throw Error(`No peer found for node identifier ${q(nodeId)}.`); } return peerId; }; @@ -1539,7 +1539,7 @@ const makeDaemonCore = async ( } } } - throw new Error('Cannot connect to peer: no supported addresses'); + throw Error('Cannot connect to peer: no supported addresses'); }, context.cancel, context.cancelled, @@ -1600,7 +1600,7 @@ const makeDaemonCore = async ( await formulaGraphJobs.enqueue(); const controller = provideController(id); console.log('Cancelled:'); - await controller.context.cancel(new Error('Invitation accepted')); + await controller.context.cancel(Error('Invitation accepted')); await E(hostAgent).write([guestName], guestHandleId); @@ -1677,7 +1677,7 @@ const makeDaemonCore = async ( } const id = petStore.identifyLocal(petName); if (id === undefined) { - throw new Error(`Unknown pet name ${petName}`); + throw Error(`Unknown pet name ${petName}`); } const { number: formulaNumber } = parseId(id); const formula = await getFormulaForId(id); diff --git a/packages/daemon/src/directory.js b/packages/daemon/src/directory.js index 3852f6dd5d..5cbc455830 100644 --- a/packages/daemon/src/directory.js +++ b/packages/daemon/src/directory.js @@ -34,7 +34,7 @@ export const makeDirectoryMaker = ({ const id = petStore.identifyLocal(headName); if (id === undefined) { - throw new TypeError(`Unknown pet name: ${q(headName)}`); + throw TypeError(`Unknown pet name: ${q(headName)}`); } const value = provide(id, 'hub'); return tailNames.reduce( @@ -59,7 +59,7 @@ export const makeDirectoryMaker = ({ */ const lookupTailNameHub = async petNamePath => { if (petNamePath.length === 0) { - throw new TypeError(`Empty pet name path`); + throw TypeError(`Empty pet name path`); } const headPath = petNamePath.slice(0, -1); const tailName = petNamePath[petNamePath.length - 1]; @@ -193,7 +193,7 @@ export const makeDirectoryMaker = ({ const id = await E(fromHub).identify(fromName); if (id === undefined) { - throw new Error(`Unknown name: ${q(fromPath)}`); + throw Error(`Unknown name: ${q(fromPath)}`); } // First write to the "to" hub so that the original name is preserved on the // "from" hub in case of failure. @@ -208,7 +208,7 @@ export const makeDirectoryMaker = ({ const { hub: toHub, name: toName } = await lookupTailNameHub(toPath); const id = await fromHub.identify(fromName); if (id === undefined) { - throw new Error(`Unknown name: ${q(fromPath)}`); + throw Error(`Unknown name: ${q(fromPath)}`); } await toHub.write([toName], id); }; diff --git a/packages/daemon/src/formula-identifier.js b/packages/daemon/src/formula-identifier.js index 1a89c6db73..b5e1574846 100644 --- a/packages/daemon/src/formula-identifier.js +++ b/packages/daemon/src/formula-identifier.js @@ -34,7 +34,7 @@ export const assertValidId = (id, petName) => { if (petName !== undefined) { message += ` for pet name ${q(petName)}`; } - throw new Error(message); + throw Error(message); } }; diff --git a/packages/daemon/src/host.js b/packages/daemon/src/host.js index 2a39892c6d..f54e4cbfc9 100644 --- a/packages/daemon/src/host.js +++ b/packages/daemon/src/host.js @@ -195,7 +195,7 @@ export const makeHostMaker = ({ assertPetNamePath(resultName); } if (petNamePaths.length !== codeNames.length) { - throw new Error('Evaluator requires one pet name for each code name'); + throw Error('Evaluator requires one pet name for each code name'); } /** @type {DeferredTasks} */ @@ -207,14 +207,14 @@ export const makeHostMaker = ({ const endowmentFormulaIdsOrPaths = petNamePaths.map( (petNameOrPath, index) => { if (typeof codeNames[index] !== 'string') { - throw new Error(`Invalid endowment name: ${q(codeNames[index])}`); + throw Error(`Invalid endowment name: ${q(codeNames[index])}`); } const petNamePath = petNamePathFrom(petNameOrPath); if (petNamePath.length === 1) { const id = petStore.identifyLocal(petNamePath[0]); if (id === undefined) { - throw new Error(`Unknown pet name ${q(petNamePath[0])}`); + throw Error(`Unknown pet name ${q(petNamePath[0])}`); } return id; } @@ -310,7 +310,7 @@ export const makeHostMaker = ({ ) => { const bundleId = petStore.identifyLocal(bundleName); if (bundleId === undefined) { - throw new TypeError(`Unknown pet name for bundle: ${q(bundleName)}`); + throw TypeError(`Unknown pet name for bundle: ${q(bundleName)}`); } const { tasks, workerId, powersId } = prepareMakeCaplet( @@ -538,10 +538,10 @@ export const makeHostMaker = ({ }; /** @type {EndoHost['cancel']} */ - const cancel = async (petName, reason = new Error('Cancelled')) => { + const cancel = async (petName, reason = Error('Cancelled')) => { const id = petStore.identifyLocal(petName); if (id === undefined) { - throw new TypeError(`Unknown pet name: ${q(petName)}`); + throw TypeError(`Unknown pet name: ${q(petName)}`); } return cancelValue(id, reason); }; diff --git a/packages/daemon/src/mail.js b/packages/daemon/src/mail.js index b205583d5d..3a83b6a3c8 100644 --- a/packages/daemon/src/mail.js +++ b/packages/daemon/src/mail.js @@ -125,15 +125,15 @@ export const makeMailboxMaker = ({ provide }) => { typeof messageNumber !== 'number' || messageNumber >= Number.MAX_SAFE_INTEGER ) { - throw new Error(`Invalid request number ${q(messageNumber)}`); + throw Error(`Invalid request number ${q(messageNumber)}`); } const message = messages.get(messageNumber); if (message === undefined) { - throw new Error(`Invalid request, ${q(messageNumber)}`); + throw Error(`Invalid request, ${q(messageNumber)}`); } const id = petStore.identifyLocal(resolutionName); if (id === undefined) { - throw new TypeError( + throw TypeError( `No formula exists for the pet name ${q(resolutionName)}`, ); } @@ -152,7 +152,7 @@ export const makeMailboxMaker = ({ provide }) => { const req = /** @type {Request} */ (message); const { responder } = E.get(req); E.sendOnly(responder).respondId( - harden(Promise.reject(harden(new Error(reason)))), + harden(Promise.reject(harden(Error(reason)))), ); } }; @@ -161,21 +161,21 @@ export const makeMailboxMaker = ({ provide }) => { const send = async (toName, strings, edgeNames, petNames) => { const toId = petStore.identifyLocal(toName); if (toId === undefined) { - throw new Error(`Unknown recipient ${toName}`); + throw Error(`Unknown recipient ${toName}`); } const to = /** @type {Handle} */ (await provide(toId)); petNames.forEach(assertPetName); edgeNames.forEach(assertPetName); if (petNames.length !== edgeNames.length) { - throw new Error( + throw Error( `Message must have one edge name (${q( edgeNames.length, )}) for every pet name (${q(petNames.length)})`, ); } if (strings.length < petNames.length) { - throw new Error( + throw Error( `Message must have one string before every value delivered`, ); } @@ -183,7 +183,7 @@ export const makeMailboxMaker = ({ provide }) => { const ids = petNames.map(petName => { const id = petStore.identifyLocal(petName); if (id === undefined) { - throw new Error(`Unknown pet name ${q(petName)}`); + throw Error(`Unknown pet name ${q(petName)}`); } return id; }); @@ -207,11 +207,11 @@ export const makeMailboxMaker = ({ provide }) => { typeof messageNumber !== 'number' || messageNumber >= Number.MAX_SAFE_INTEGER ) { - throw new Error(`Invalid request number ${messageNumber}`); + throw Error(`Invalid request number ${messageNumber}`); } const message = messages.get(messageNumber); if (message === undefined) { - throw new Error(`Invalid request number ${messageNumber}`); + throw Error(`Invalid request number ${messageNumber}`); } const { dismisser } = E.get(message); return E(dismisser).dismiss(); @@ -225,24 +225,24 @@ export const makeMailboxMaker = ({ provide }) => { typeof messageNumber !== 'number' || messageNumber >= Number.MAX_SAFE_INTEGER ) { - throw new Error(`Invalid message number ${q(messageNumber)}`); + throw Error(`Invalid message number ${q(messageNumber)}`); } const message = messages.get(messageNumber); if (message === undefined) { - throw new Error(`No such message with number ${q(messageNumber)}`); + throw Error(`No such message with number ${q(messageNumber)}`); } if (message.type !== 'package') { - throw new Error(`Message must be a package ${q(messageNumber)}`); + throw Error(`Message must be a package ${q(messageNumber)}`); } const index = message.names.lastIndexOf(edgeName); if (index === -1) { - throw new Error( + throw Error( `No reference named ${q(edgeName)} in message ${q(messageNumber)}`, ); } const id = message.ids[index]; if (id === undefined) { - throw new Error( + throw Error( `panic: message must contain a formula for every name, including the name ${q( edgeName, )} at ${q(index)}`, @@ -264,7 +264,7 @@ export const makeMailboxMaker = ({ provide }) => { const toId = petStore.identifyLocal(toName); if (toId === undefined) { - throw new Error(`Unknown recipient ${toName}`); + throw Error(`Unknown recipient ${toName}`); } const to = /** @type {Handle} */ (await provide(toId)); @@ -293,7 +293,7 @@ export const makeMailboxMaker = ({ provide }) => { const open = envelope => { const message = outbox.get(envelope); if (message === undefined) { - throw new Error('Mail fraud: unrecognized parcel'); + throw Error('Mail fraud: unrecognized parcel'); } return message; }; @@ -308,7 +308,7 @@ export const makeMailboxMaker = ({ provide }) => { const sender = /** @type {Promise} */ (provide(allegedFromId)); const message = await E(sender).open(envelope); if (allegedFromId !== message.from) { - throw new Error('Mail fraud: alleged sender does not recognize parcel'); + throw Error('Mail fraud: alleged sender does not recognize parcel'); } deliver(message); }; diff --git a/packages/daemon/src/multimap.js b/packages/daemon/src/multimap.js index b7e1f86b3a..3157f4aedd 100644 --- a/packages/daemon/src/multimap.js +++ b/packages/daemon/src/multimap.js @@ -73,7 +73,7 @@ export const makeBidirectionalMultimap = () => { const existingKey = valueForKey.get(value); if (hasExistingMapping && existingKey !== key) { - throw new Error( + throw Error( `May not remap key ${q(existingKey)} of existing value to new key ${q( key, )}. Delete the original mapping first.`, diff --git a/packages/daemon/src/networks/loopback.js b/packages/daemon/src/networks/loopback.js index f728c9092d..314269b352 100644 --- a/packages/daemon/src/networks/loopback.js +++ b/packages/daemon/src/networks/loopback.js @@ -13,7 +13,7 @@ export const makeLoopbackNetwork = gateway => { supports: address => new URL(address).protocol === 'loop:', connect: address => { if (address !== 'loop:') { - throw new Error( + throw Error( 'Failed invariant: loopback only supports "loop:" address', ); } diff --git a/packages/daemon/src/pet-name.js b/packages/daemon/src/pet-name.js index abaf402e98..978b2a4adb 100644 --- a/packages/daemon/src/pet-name.js +++ b/packages/daemon/src/pet-name.js @@ -14,7 +14,7 @@ export const isPetName = petName => validNamePattern.test(petName); */ export const assertPetName = petName => { if (typeof petName !== 'string' || !isPetName(petName)) { - throw new Error(`Invalid pet name ${q(petName)}`); + throw Error(`Invalid pet name ${q(petName)}`); } }; @@ -23,7 +23,7 @@ export const assertPetName = petName => { */ export const assertPetNamePath = petNamePath => { if (!Array.isArray(petNamePath) || petNamePath.length < 1) { - throw new Error(`Invalid pet name path`); + throw Error(`Invalid pet name path`); } for (const petName of petNamePath) { assertPetName(petName); diff --git a/packages/daemon/src/pet-sitter.js b/packages/daemon/src/pet-sitter.js index 03fc0b9b83..5d9d2025aa 100644 --- a/packages/daemon/src/pet-sitter.js +++ b/packages/daemon/src/pet-sitter.js @@ -23,7 +23,7 @@ export const makePetSitter = (petStore, specialNames) => { return specialNames[petName]; } if (!isPetName(petName)) { - throw new Error( + throw Error( `Invalid pet name ${q(petName)} and not one of ${Object.keys( specialNames, ).join(', ')}`, @@ -39,7 +39,7 @@ export const makePetSitter = (petStore, specialNames) => { const idRecordForName = petName => { const id = identifyLocal(petName); if (id === undefined) { - throw new Error(`Formula does not exist for pet name ${q(petName)}`); + throw Error(`Formula does not exist for pet name ${q(petName)}`); } return parseId(id); }; diff --git a/packages/daemon/src/pet-store.js b/packages/daemon/src/pet-store.js index b37e5a67b0..44eedc4664 100644 --- a/packages/daemon/src/pet-store.js +++ b/packages/daemon/src/pet-store.js @@ -164,7 +164,7 @@ export const makePetStoreMaker = (filePowers, config) => { assertValidName(petName); const formulaIdentifier = idsToPetNames.getKey(petName); if (formulaIdentifier === undefined) { - throw new Error( + throw Error( `Formula does not exist for pet name ${JSON.stringify(petName)}`, ); } @@ -188,7 +188,7 @@ export const makePetStoreMaker = (filePowers, config) => { const formulaIdentifier = idsToPetNames.getKey(fromName); const overwrittenId = idsToPetNames.getKey(toName); if (formulaIdentifier === undefined) { - throw new Error( + throw Error( `Formula does not exist for pet name ${JSON.stringify(fromName)}`, ); } @@ -248,9 +248,7 @@ export const makePetStoreMaker = (filePowers, config) => { assertValidName, ) => { if (!isValidNumber(formulaNumber)) { - throw new Error( - `Invalid formula number for pet store ${q(formulaNumber)}`, - ); + throw Error(`Invalid formula number for pet store ${q(formulaNumber)}`); } const prefix = formulaNumber.slice(0, 2); const suffix = formulaNumber.slice(2); diff --git a/packages/daemon/src/remote-control.js b/packages/daemon/src/remote-control.js index 595660315c..a585e11e9f 100644 --- a/packages/daemon/src/remote-control.js +++ b/packages/daemon/src/remote-control.js @@ -43,7 +43,7 @@ export const makeRemoteControlProvider = localNodeId => { // TODO: For the case where we leave a peer wedged half-open, we // will need health checks. Promise.resolve( - proposedCancel(new Error('Already accepted a connection.')), + proposedCancel(Error('Already accepted a connection.')), ).then(proposedDispose); return accepted(remoteGateway, cancelCurrent, currentCancelled); }, @@ -95,7 +95,7 @@ export const makeRemoteControlProvider = localNodeId => { // so cancel the inbound. Promise.resolve( proposedCancel( - new Error( + Error( 'Connection refused: already connected (crossed hellos, connect bias)', ), ), @@ -144,7 +144,7 @@ export const makeRemoteControlProvider = localNodeId => { // We receive an inbound connection. // Ditch our outbound connection. cancelCurrent( - new Error( + Error( 'Connection abandoned: accepted new connection (crossed hellos, accept bias)', ), ); diff --git a/packages/daemon/src/serve-private-port-http.js b/packages/daemon/src/serve-private-port-http.js index f95d0a4aaf..685827ea12 100644 --- a/packages/daemon/src/serve-private-port-http.js +++ b/packages/daemon/src/serve-private-port-http.js @@ -88,12 +88,12 @@ export const servePrivatePortHttp = ( const host = request.headers.host; if (host === undefined) { - throw new Error('Host header required'); + throw Error('Host header required'); } const match = /^([0-9a-f]{32})\.endo\.localhost:([1-9][0-9]{0,4})$/.exec(host); if (match === null) { - throw new Error(`Invalid host ${host}`); + throw Error(`Invalid host ${host}`); } const [_, formulaNumber, portNumber] = match; // eslint-disable-next-line no-use-before-define diff --git a/packages/daemon/src/web-server-node-powers.js b/packages/daemon/src/web-server-node-powers.js index 370a1ff78b..fbfaa4fe86 100644 --- a/packages/daemon/src/web-server-node-powers.js +++ b/packages/daemon/src/web-server-node-powers.js @@ -116,7 +116,7 @@ export const makeHttpPowers = ({ http, ws }) => { socket.on('message', (bytes, isBinary) => { if (!isBinary) { - abort(new Error('expected binary')); + abort(Error('expected binary')); return; } // TODO Ignoring back-pressure signal: @@ -171,7 +171,7 @@ export const makeHttpPowers = ({ http, ws }) => { cancelled.catch(() => server.close()); const address = server.address(); if (address === null || typeof address === 'string') { - reject(new Error('expected listener to be assigned a port')); + reject(Error('expected listener to be assigned a port')); } else { resolve(address.port); } diff --git a/packages/daemon/src/web-server-node.js b/packages/daemon/src/web-server-node.js index b01690e69b..378a45ff2a 100644 --- a/packages/daemon/src/web-server-node.js +++ b/packages/daemon/src/web-server-node.js @@ -105,7 +105,7 @@ export const make = async (_powers, context) => { const connect = (connection, request) => { if (request.url !== `/${accessToken}/`) { - connection.writer.throw(new Error(`Invalid access token.`)); + connection.writer.throw(Error(`Invalid access token.`)); return; } diff --git a/packages/daemon/src/worker-node.js b/packages/daemon/src/worker-node.js index b0ca493c0a..73c1b3ba76 100644 --- a/packages/daemon/src/worker-node.js +++ b/packages/daemon/src/worker-node.js @@ -21,7 +21,7 @@ const powers = makePowers({ fs, url }); const { promise: cancelled, reject: cancel } = /** @type {PromiseKit} */ (makePromiseKit()); -process.once('SIGINT', () => cancel(new Error('SIGINT'))); +process.once('SIGINT', () => cancel(Error('SIGINT'))); // @ts-ignore Yes, we can assign to exitCode, typedoc. process.exitCode = 1; diff --git a/packages/daemon/test/context-consumer.js b/packages/daemon/test/context-consumer.js index 6d7bb1819d..b465437fdf 100644 --- a/packages/daemon/test/context-consumer.js +++ b/packages/daemon/test/context-consumer.js @@ -17,7 +17,7 @@ export const make = async (_powers, context) => { } catch { return 'cancelled'; } - throw new Error('should have been cancelled'); + throw Error('should have been cancelled'); }, }); }; diff --git a/packages/daemon/test/endo.test.js b/packages/daemon/test/endo.test.js index 4e6cd36ec9..9607c77b12 100644 --- a/packages/daemon/test/endo.test.js +++ b/packages/daemon/test/endo.test.js @@ -251,7 +251,7 @@ test('lifecycle', async t => { const host = E(bootstrap).host(); await E(host).provideWorker(['worker']); await E(host).cancel('worker'); - cancel(new Error('Cancelled')); + cancel(Error('Cancelled')); await closed.catch(() => {}); t.pass(); diff --git a/packages/daemon/test/failed-hub.js b/packages/daemon/test/failed-hub.js index 0ad941e20f..9b5a676cba 100644 --- a/packages/daemon/test/failed-hub.js +++ b/packages/daemon/test/failed-hub.js @@ -7,7 +7,7 @@ export const make = () => { M.interface('FailedHub', {}, { defaultGuards: 'passable' }), { write() { - throw new Error('I had one job.'); + throw Error('I had one job.'); }, }, ); diff --git a/packages/daemon/test/move-hub.js b/packages/daemon/test/move-hub.js index 82e37c091e..d4fcdaae11 100644 --- a/packages/daemon/test/move-hub.js +++ b/packages/daemon/test/move-hub.js @@ -20,7 +20,7 @@ export const make = () => { */ const parsePetNamePath = petNamePath => { if (!Array.isArray(petNamePath) || petNamePath.length !== 1) { - throw new Error(`Unexpected pet name path ${q(petNamePath)}`); + throw Error(`Unexpected pet name path ${q(petNamePath)}`); } return petNamePath[0]; }; @@ -31,7 +31,7 @@ export const make = () => { const expectGetId = petName => { const id = nameToId.get(petName); if (id === undefined) { - throw new Error(`Unknown pet name ${q(petName)}`); + throw Error(`Unknown pet name ${q(petName)}`); } return id; }; diff --git a/packages/daemon/test/pubsub.test.js b/packages/daemon/test/pubsub.test.js index ca46e3cfbc..2844016dfe 100644 --- a/packages/daemon/test/pubsub.test.js +++ b/packages/daemon/test/pubsub.test.js @@ -118,7 +118,7 @@ test('change topic terminates with error', async (/** @type {import('ava').Asser const subscription = subscribe(); - await publisher.throw(new TypeError('sentinel')); + await publisher.throw(TypeError('sentinel')); await t.throwsAsync(() => subscription.next(), { instanceOf: TypeError, diff --git a/packages/daemon/test/remote-control.test.js b/packages/daemon/test/remote-control.test.js index 8a184e1b9a..754336ae72 100644 --- a/packages/daemon/test/remote-control.test.js +++ b/packages/daemon/test/remote-control.test.js @@ -11,7 +11,7 @@ const makeFakeGateway = () => M.interface('FakeGateway', {}, { defaultGuards: 'passable' }), { provide() { - throw new Error('Fake gateway provides nothing'); + throw Error('Fake gateway provides nothing'); }, }, ); @@ -29,7 +29,7 @@ test('remote control connects from initial state and propagates cancellation', a ); t.is(receivedBobGateway, bobGateway); - cancelBob(new Error('Peer cancelled')); + cancelBob(Error('Peer cancelled')); await t.throwsAsync(() => bobCancelled); }); @@ -41,7 +41,7 @@ test('remote control accepts from initial state and propagates cancellation', as bobRemoteControl.accept(bobGateway, cancelBob, bobCancelled); - cancelBob(new Error('Peer cancelled')); + cancelBob(Error('Peer cancelled')); await t.throwsAsync(() => bobCancelled); }); @@ -61,7 +61,7 @@ test('remote control connect uses existing connection after accept', async t => ); t.is(finalBobGateway, bobGateway1); - cancelBob1(new Error('Peer cancelled')); + cancelBob1(Error('Peer cancelled')); await t.throwsAsync(() => bob1Cancelled); await t.throwsAsync(() => bob2Cancelled); }); @@ -89,7 +89,7 @@ test('remote control drops outbound connect when accepting from lower id', async ); t.is(finalBobGateway, bobGateway1); - cancelBob3(new Error('Peer cancelled')); + cancelBob3(Error('Peer cancelled')); await t.throwsAsync(() => bob1Cancelled); await t.throwsAsync(() => bob2Cancelled); await t.throwsAsync(() => bob3Cancelled); @@ -115,7 +115,7 @@ test('remote control keeps outbound connect when accepting from higher id', asyn ); t.is(finalBobGateway, bobGateway2); - cancelBob3(new Error('Peer cancelled')); + cancelBob3(Error('Peer cancelled')); await t.throwsAsync(() => bob2Cancelled); await t.throwsAsync(() => bob3Cancelled); }); @@ -139,7 +139,7 @@ test('remote control reuses existing connection when reconnecting', async t => { ); t.is(bobGateway2, bobGateway1); - cancelBob1(new Error('Peer cancelled')); + cancelBob1(Error('Peer cancelled')); await t.throwsAsync(() => bob1Cancelled); await t.throwsAsync(() => bob2Cancelled); }); @@ -156,7 +156,7 @@ test('remote control establishes new connection when reconnecting after disconne bob1Cancelled, disposeBob1, ); - cancelBob1(new Error('Disconnect')); + cancelBob1(Error('Disconnect')); await t.throwsAsync(() => bob1Cancelled); // Depending on the interleaving of events, it is possible that we need to // wait for the remote control to asynchronously transition to the initial @@ -181,7 +181,7 @@ test('remote control establishes new connection when reconnecting after disconne ); t.is(bobGateway3, bobGateway2); - cancelBob2(new Error('Peer cancelled')); + cancelBob2(Error('Peer cancelled')); await t.throwsAsync(() => bob2Cancelled); await t.throwsAsync(() => bob3Cancelled); }); @@ -206,7 +206,7 @@ test('remote control accept after accept', async t => { ); t.is(bobGateway3, bobGateway1); - cancelBob1(new Error('Peer cancelled')); + cancelBob1(Error('Peer cancelled')); await t.throwsAsync(() => bob1Cancelled); await t.throwsAsync(() => bob2Cancelled); }); @@ -232,7 +232,7 @@ test('remote control connects first, ignores second, entagles cancellation of se ); t.is(receivedBobGateway2, bobGateway1); - cancelBob2(new Error('Peer cancelled')); + cancelBob2(Error('Peer cancelled')); await t.throwsAsync(() => bob1Cancelled); await t.throwsAsync(() => bob2Cancelled); }); @@ -261,7 +261,7 @@ test('remote control connects first, ignores second, entagles cancellation of fi ); t.is(receivedBobGateway2, bobGateway1); - cancelBob1(new Error('Peer cancelled')); + cancelBob1(Error('Peer cancelled')); await t.throwsAsync(() => bob1Cancelled); await t.throwsAsync(() => bob2Cancelled); }); @@ -298,7 +298,7 @@ test('remote control connects first, ignores second and third, entagles cancella ); t.is(receivedBobGateway3, bobGateway1); - cancelBob1(new Error('Peer cancelled')); + cancelBob1(Error('Peer cancelled')); await t.throwsAsync(() => bob1Cancelled); await t.throwsAsync(() => bob2Cancelled); diff --git a/packages/evasive-transform/src/location-unmapper.js b/packages/evasive-transform/src/location-unmapper.js index 3df80fbbd3..1f04d68bd4 100644 --- a/packages/evasive-transform/src/location-unmapper.js +++ b/packages/evasive-transform/src/location-unmapper.js @@ -25,13 +25,13 @@ import { SourceMapConsumer } from 'source-map-js'; */ export function makeLocationUnmapper(sourceMap, ast) { if (!sourceMap) { - throw new TypeError('Invalid arguments; expected sourceMap'); + throw TypeError('Invalid arguments; expected sourceMap'); } if (!ast || typeof ast !== 'object') { - throw new TypeError('Invalid arguments; expected AST ast'); + throw TypeError('Invalid arguments; expected AST ast'); } if (!ast.loc) { - throw new TypeError('No SourceLocation found in AST'); + throw TypeError('No SourceLocation found in AST'); } try { // We rearrange the rolled-up chunk according to its sourcemap to move @@ -73,7 +73,7 @@ export function makeLocationUnmapper(sourceMap, ast) { // A source map string should be valid JSON, and if `JSON.parse()` fails, a // SyntaxError is thrown if (err instanceof SyntaxError) { - throw new TypeError(`Invalid source map: ${err}`); + throw TypeError(`Invalid source map: ${err}`); } throw err; } diff --git a/packages/pass-style/src/types.test-d.ts b/packages/pass-style/src/types.test-d.ts index 274e54a294..bb824dd27c 100644 --- a/packages/pass-style/src/types.test-d.ts +++ b/packages/pass-style/src/types.test-d.ts @@ -21,7 +21,7 @@ expectType<'bigint'>(passStyleOf(1n)); expectType<'symbol'>(passStyleOf(Symbol.for('foo'))); expectType<'null'>(passStyleOf(null)); expectType<'promise'>(passStyleOf(Promise.resolve())); -expectType<'error'>(passStyleOf(new Error())); +expectType<'error'>(passStyleOf(Error())); expectType<'tagged'>(passStyleOf(copyTagged)); expectType<'copyArray'>(passStyleOf([])); expectType<'copyRecord'>(passStyleOf({})); diff --git a/packages/ses/README.md b/packages/ses/README.md index 59b27bc2d2..bf22f12d21 100644 --- a/packages/ses/README.md +++ b/packages/ses/README.md @@ -414,7 +414,7 @@ const importHook = async specifier => { }; } } - throw new Error(`Cannot find module ${specifier}`); + throw Error(`Cannot find module ${specifier}`); }; const compartment = new Compartment({ diff --git a/packages/ses/docs/lockdown.md b/packages/ses/docs/lockdown.md index 433d7fb8c1..67380de37f 100644 --- a/packages/ses/docs/lockdown.md +++ b/packages/ses/docs/lockdown.md @@ -564,7 +564,7 @@ constructors in the compartment. ```js const c = new Compartment() c.globalThis.eval = c.globalThis.Function = function() { - throw new TypeError(); + throw TypeError(); }; ``` diff --git a/packages/ses/test/_console-error-trap/index.html b/packages/ses/test/_console-error-trap/index.html index 3c161ef420..986407466b 100644 --- a/packages/ses/test/_console-error-trap/index.html +++ b/packages/ses/test/_console-error-trap/index.html @@ -4,5 +4,5 @@ diff --git a/packages/ses/test/_console-rejection-trap/index.html b/packages/ses/test/_console-rejection-trap/index.html index 80a9b4caf2..6c3b5c65e4 100644 --- a/packages/ses/test/_console-rejection-trap/index.html +++ b/packages/ses/test/_console-rejection-trap/index.html @@ -4,5 +4,5 @@ diff --git a/packages/ses/test/import-hook.test.js b/packages/ses/test/import-hook.test.js index d66cd1e308..2288a6bc49 100644 --- a/packages/ses/test/import-hook.test.js +++ b/packages/ses/test/import-hook.test.js @@ -106,7 +106,7 @@ test('import hook returns parent compartment module source reference with differ imports: [], exports: ['meaning'], execute() { - throw new Error('should not execute'); + throw Error('should not execute'); }, }, }; @@ -472,7 +472,7 @@ test('module map hook precedes import hook', async t => { return undefined; }, importHook() { - throw new Error('not reached'); + throw Error('not reached'); }, __noNamespaceBox__: true, __options__: true, diff --git a/packages/ses/test/import-now-hook.test.js b/packages/ses/test/import-now-hook.test.js index b43cae9550..783891ffec 100644 --- a/packages/ses/test/import-now-hook.test.js +++ b/packages/ses/test/import-now-hook.test.js @@ -101,7 +101,7 @@ test('import now hook returns parent compartment module source reference with di imports: [], exports: ['meaning'], execute() { - throw new Error('should not execute'); + throw Error('should not execute'); }, }, }; @@ -457,7 +457,7 @@ test('module map hook precedes import now hook', t => { return undefined; }, importNowHook() { - throw new Error('not reached'); + throw Error('not reached'); }, __options__: true, }); diff --git a/packages/ses/test/module-map-hook.test.js b/packages/ses/test/module-map-hook.test.js index 567e5fc49c..2108dd6ea1 100644 --- a/packages/ses/test/module-map-hook.test.js +++ b/packages/ses/test/module-map-hook.test.js @@ -104,7 +104,7 @@ test('module map hook returns parent compartment module source reference with di imports: [], exports: ['meaning'], execute() { - throw new Error('should not execute'); + throw Error('should not execute'); }, }, }; @@ -471,7 +471,7 @@ test('module map precedes module map hook', t => { }, }, moduleMapHook() { - throw new Error('not reached'); + throw Error('not reached'); }, __options__: true, }); diff --git a/packages/ses/test/module-map.test.js b/packages/ses/test/module-map.test.js index 77ac020a08..7e3677fce6 100644 --- a/packages/ses/test/module-map.test.js +++ b/packages/ses/test/module-map.test.js @@ -150,7 +150,7 @@ test('module map primed with parent compartment module source reference with dif imports: [], exports: ['meaning'], execute() { - throw new Error('should not execute'); + throw Error('should not execute'); }, }, }, @@ -387,7 +387,7 @@ test('module map precedes module map hook', t => { }, }, moduleMapHook() { - throw new Error('not reached'); + throw Error('not reached'); }, __options__: true, }); diff --git a/packages/ses/test/tame-legacy-regenerator-helper.test.js b/packages/ses/test/tame-legacy-regenerator-helper.test.js index 27dc07ffa5..e2c73f6261 100644 --- a/packages/ses/test/tame-legacy-regenerator-helper.test.js +++ b/packages/ses/test/tame-legacy-regenerator-helper.test.js @@ -8,7 +8,7 @@ test('lockdown Iterator.prototype[@@iterator] is tamed', t => { Object.getPrototypeOf([].values()), ); const desc = Object.getOwnPropertyDescriptor(IteratorProto, Symbol.iterator); - if (!desc || !desc.get || !desc.set) throw new Error('unreachable'); + if (!desc || !desc.get || !desc.set) throw Error('unreachable'); t.is(desc.configurable || desc.enumerable, false); t.is(desc.value, undefined);