diff --git a/packages/captp/package.json b/packages/captp/package.json index 535b55ac2c..2ca2a07740 100644 --- a/packages/captp/package.json +++ b/packages/captp/package.json @@ -52,6 +52,7 @@ "c8": "^7.14.0" }, "dependencies": { + "@endo/errors": "^1.0.2", "@endo/eventual-send": "^1.1.0", "@endo/marshal": "^1.1.0", "@endo/nat": "^5.0.2", diff --git a/packages/captp/src/atomics.js b/packages/captp/src/atomics.js index db03de5c88..318862fae6 100644 --- a/packages/captp/src/atomics.js +++ b/packages/captp/src/atomics.js @@ -1,6 +1,6 @@ /// -const { details: X, Fail } = assert; +import { X, Fail } from '@endo/errors'; // This is a pathological minimum, but exercised by the unit test. export const MIN_DATA_BUFFER_LENGTH = 1; @@ -154,7 +154,7 @@ export const makeAtomicsTrapGuest = transferBuffer => { // // TODO: It would be nice to use an error type, but captp is just too // noisy with spurious "Temporary logging of sent error" messages. - // it.throw(assert.error(X`Trap host has not finished`)); + // it.throw(makeError(X`Trap host has not finished`)); it.throw(null); // eslint-disable-next-line no-bitwise diff --git a/packages/captp/src/captp.js b/packages/captp/src/captp.js index 3171aa72ce..6805d5dd06 100644 --- a/packages/captp/src/captp.js +++ b/packages/captp/src/captp.js @@ -12,14 +12,13 @@ import { Remotable, Far, makeMarshal, QCLASS } from '@endo/marshal'; import { E, HandledPromise } from '@endo/eventual-send'; import { isPromise, makePromiseKit } from '@endo/promise-kit'; +import { X, Fail, errorNote } from '@endo/errors'; import { makeTrap } from './trap.js'; import { makeFinalizingMap } from './finalize.js'; export { E }; -const { details: X, Fail } = assert; - const WELL_KNOWN_SLOT_PROPERTIES = harden(['answerID', 'questionID', 'target']); /** @@ -670,7 +669,7 @@ export const makeCapTP = ( if (!e) { Fail`trapGuest expected trapHost AsyncIterator(${questionID}) to be done, but it wasn't`; } - assert.note(e, X`trapHost AsyncIterator(${questionID}) threw`); + errorNote(e, X`trapHost AsyncIterator(${questionID}) threw`); throw e; } }; diff --git a/packages/captp/test/traplib.js b/packages/captp/test/traplib.js index 0c796531f6..41fdf09029 100644 --- a/packages/captp/test/traplib.js +++ b/packages/captp/test/traplib.js @@ -2,12 +2,11 @@ /// import { Far } from '@endo/marshal'; +import { X, Fail } from '@endo/errors'; import { E, makeCapTP } from '../src/captp.js'; import { makeAtomicsTrapGuest, makeAtomicsTrapHost } from '../src/atomics.js'; -const { details: X, Fail } = assert; - export const createHostBootstrap = makeTrapHandler => { // Create a remotable that has a syncable return value. return Far('test traps', { diff --git a/packages/captp/test/worker.js b/packages/captp/test/worker.js index 2dfd477bcc..0def2ef38d 100644 --- a/packages/captp/test/worker.js +++ b/packages/captp/test/worker.js @@ -4,10 +4,9 @@ import '@endo/init/pre-remoting.js'; import '@endo/init/debug.js'; import { parentPort } from 'worker_threads'; +import { Fail } from '@endo/errors'; import { makeGuest, makeHost } from './traplib.js'; -const { Fail } = assert; - let dispatch; parentPort.addListener('message', obj => { switch (obj.type) { diff --git a/packages/check-bundle/lite.js b/packages/check-bundle/lite.js index c81f191ba9..b8c54f2e60 100644 --- a/packages/check-bundle/lite.js +++ b/packages/check-bundle/lite.js @@ -4,7 +4,7 @@ import { decodeBase64 } from '@endo/base64/decode.js'; import { parseArchive } from '@endo/compartment-mapper/import-archive.js'; -const { Fail, details: d, quote: q } = assert; +import { Fail, X, q } from '@endo/errors'; /** * Verifies that a bundle passes its own integrity checks or rejects the @@ -25,7 +25,7 @@ export const checkBundle = async ( assert.typeof( bundle, 'object', - d`checkBundle cannot hash non-bundle, must be of type object, got ${q( + X`checkBundle cannot hash non-bundle, must be of type object, got ${q( bundle, )}`, ); @@ -56,7 +56,7 @@ export const checkBundle = async ( assert.typeof( moduleFormat, 'string', - d`checkBundle cannot hash non-bundle, moduleFormat must be a string, got ${typeof moduleFormat}`, + X`checkBundle cannot hash non-bundle, moduleFormat must be a string, got ${typeof moduleFormat}`, ); if (moduleFormat === 'endoZipBase64') { @@ -64,12 +64,12 @@ export const checkBundle = async ( assert.typeof( endoZipBase64, 'string', - d`checkBundle cannot hash non-bundle, property 'endoZipBase64' must be a string, got ${typeof endoZipBase64}`, + X`checkBundle cannot hash non-bundle, property 'endoZipBase64' must be a string, got ${typeof endoZipBase64}`, ); assert.typeof( endoZipBase64Sha512, 'string', - d`checkBundle cannot bundle without the property 'endoZipBase64Sha512', which must be a string, got ${typeof endoZipBase64Sha512}`, + X`checkBundle cannot bundle without the property 'endoZipBase64Sha512', which must be a string, got ${typeof endoZipBase64Sha512}`, ); const bytes = decodeBase64(endoZipBase64); const { sha512: parsedSha512 } = await parseArchive(bytes, bundleName, { diff --git a/packages/check-bundle/package.json b/packages/check-bundle/package.json index 955b9d6a12..84be999f5c 100644 --- a/packages/check-bundle/package.json +++ b/packages/check-bundle/package.json @@ -40,7 +40,8 @@ }, "dependencies": { "@endo/base64": "^1.0.1", - "@endo/compartment-mapper": "^1.1.0" + "@endo/compartment-mapper": "^1.1.0", + "@endo/errors": "^1.0.2" }, "devDependencies": { "@endo/bundle-source": "^3.0.2", diff --git a/packages/common/from-unique-entries.js b/packages/common/from-unique-entries.js index a2daad065f..252f0bdd1a 100644 --- a/packages/common/from-unique-entries.js +++ b/packages/common/from-unique-entries.js @@ -1,8 +1,8 @@ +import { q, Fail } from '@endo/errors'; + const { fromEntries } = Object; const { ownKeys } = Reflect; -const { quote: q, Fail } = assert; - /** * Throws if multiple entries use the same property name. Otherwise acts * like `Object.fromEntries` but hardens the result. diff --git a/packages/common/package.json b/packages/common/package.json index 593327bd65..eb3a13a992 100644 --- a/packages/common/package.json +++ b/packages/common/package.json @@ -41,6 +41,7 @@ "test:xs": "exit 0" }, "dependencies": { + "@endo/errors": "^1.0.2", "@endo/eventual-send": "^1.1.0", "@endo/promise-kit": "^1.0.2" }, diff --git a/packages/common/test/test-apply-labeling-error.js b/packages/common/test/test-apply-labeling-error.js index e042e29831..e43603f17f 100644 --- a/packages/common/test/test-apply-labeling-error.js +++ b/packages/common/test/test-apply-labeling-error.js @@ -1,7 +1,8 @@ import { test } from './prepare-test-env-ava.js'; -import { applyLabelingError } from '../apply-labeling-error.js'; -const { Fail } = assert; +// eslint-disable-next-line import/order +import { Fail } from '@endo/errors'; +import { applyLabelingError } from '../apply-labeling-error.js'; test('test applyLabelingError', async t => { t.is( diff --git a/packages/common/throw-labeled.js b/packages/common/throw-labeled.js index 38f90de1ab..858476b460 100644 --- a/packages/common/throw-labeled.js +++ b/packages/common/throw-labeled.js @@ -1,4 +1,4 @@ -const { details: X } = assert; +import { X, makeError, errorNote } from '@endo/errors'; /** * Given an error `innerErr` and a `label`, throws a similar @@ -14,11 +14,8 @@ export const throwLabeled = (innerErr, label, ErrorConstructor = undefined) => { if (typeof label === 'number') { label = `[${label}]`; } - const outerErr = assert.error( - `${label}: ${innerErr.message}`, - ErrorConstructor, - ); - assert.note(outerErr, X`Caused by ${innerErr}`); + const outerErr = makeError(`${label}: ${innerErr.message}`, ErrorConstructor); + errorNote(outerErr, X`Caused by ${innerErr}`); throw outerErr; }; harden(throwLabeled); diff --git a/packages/daemon/package.json b/packages/daemon/package.json index e1e7c502a6..a6d3b0d568 100644 --- a/packages/daemon/package.json +++ b/packages/daemon/package.json @@ -40,6 +40,7 @@ }, "dependencies": { "@endo/captp": "^4.0.2", + "@endo/errors": "^1.0.2", "@endo/eventual-send": "^1.1.0", "@endo/far": "^1.0.2", "@endo/lockdown": "^1.0.2", diff --git a/packages/daemon/src/daemon.js b/packages/daemon/src/daemon.js index 3e1f2fae76..d229a6bd87 100644 --- a/packages/daemon/src/daemon.js +++ b/packages/daemon/src/daemon.js @@ -17,10 +17,9 @@ import url from 'url'; import { E, Far } from '@endo/far'; import { makePromiseKit } from '@endo/promise-kit'; +import { q } from '@endo/errors'; import { makeNodeNetstringCapTP } from './connection.js'; -const { quote: q } = assert; - const { promise: cancelled, reject: cancel } = makePromiseKit(); // TODO thread through command arguments. diff --git a/packages/errors/index.js b/packages/errors/index.js index 9812aec3be..077f803cf1 100644 --- a/packages/errors/index.js +++ b/packages/errors/index.js @@ -71,4 +71,10 @@ export { quote, redacted, throwRedacted, + // conventional abbreviations and aliases + bare as b, + quote as q, + redacted as X, + throwRedacted as Fail, + note as errorNote, }; diff --git a/packages/eventual-send/src/E.js b/packages/eventual-send/src/E.js index 29ff9e7ad1..f04c0423f6 100644 --- a/packages/eventual-send/src/E.js +++ b/packages/eventual-send/src/E.js @@ -53,7 +53,7 @@ const makeEProxyHandler = (recipient, HandledPromise) => // Reject the async function call return HandledPromise.reject( assert.error( - X`Unexpected receiver for "${propertyKey}" method of E(${q( + X`Unexpected receiver for "${q(propertyKey)}" method of E(${q( recipient, )})`, ), diff --git a/packages/exo/package.json b/packages/exo/package.json index e9b673f32b..5f0412b54e 100644 --- a/packages/exo/package.json +++ b/packages/exo/package.json @@ -33,6 +33,7 @@ }, "dependencies": { "@endo/common": "^1.0.2", + "@endo/errors": "^1.0.2", "@endo/env-options": "^1.1.0", "@endo/eventual-send": "^1.1.0", "@endo/far": "^1.0.2", diff --git a/packages/exo/src/exo-makers.js b/packages/exo/src/exo-makers.js index 54b1904376..82500fcc3a 100644 --- a/packages/exo/src/exo-makers.js +++ b/packages/exo/src/exo-makers.js @@ -2,9 +2,9 @@ import { environmentOptionsListHas } from '@endo/env-options'; import { objectMap } from '@endo/common/object-map.js'; +import { Fail, q } from '@endo/errors'; import { defendPrototype, defendPrototypeKit } from './exo-tools.js'; -const { Fail, quote: q } = assert; const { create, seal, freeze, defineProperty, values } = Object; // Turn on to give each exo instance its own toStringTag value. diff --git a/packages/exo/src/exo-tools.js b/packages/exo/src/exo-tools.js index 99685f1498..478f80a19b 100644 --- a/packages/exo/src/exo-tools.js +++ b/packages/exo/src/exo-tools.js @@ -13,6 +13,7 @@ import { } from '@endo/patterns'; import { listDifference } from '@endo/common/list-difference.js'; import { objectMap } from '@endo/common/object-map.js'; +import { q, Fail } from '@endo/errors'; import { GET_INTERFACE_GUARD } from './get-interface.js'; /** @typedef {import('@endo/patterns').Method} Method */ @@ -23,7 +24,6 @@ import { GET_INTERFACE_GUARD } from './get-interface.js'; * @typedef {import('@endo/patterns').InterfaceGuard} InterfaceGuard */ -const { quote: q, Fail } = assert; const { apply, ownKeys } = Reflect; const { defineProperties, fromEntries } = Object; diff --git a/packages/exo/test/test-exo-wobbly-point.js b/packages/exo/test/test-exo-wobbly-point.js index 1ec065e125..4850ad5b2f 100644 --- a/packages/exo/test/test-exo-wobbly-point.js +++ b/packages/exo/test/test-exo-wobbly-point.js @@ -14,10 +14,11 @@ import { test } from './prepare-test-env-ava.js'; import { getMethodNames } from '@endo/eventual-send/utils.js'; import { passStyleOf, Far, GET_METHOD_NAMES } from '@endo/pass-style'; import { M } from '@endo/patterns'; -import { defineExoClass } from '../src/exo-makers.js'; + +import { Fail, q } from '@endo/errors'; import { GET_INTERFACE_GUARD } from '../src/get-interface.js'; +import { defineExoClass } from '../src/exo-makers.js'; -const { Fail, quote: q } = assert; const { apply } = Reflect; const ExoEmptyI = M.interface('ExoEmpty', {}); diff --git a/packages/exo/test/test-label-instances.js b/packages/exo/test/test-label-instances.js index 6ffafe0723..8fff031504 100644 --- a/packages/exo/test/test-label-instances.js +++ b/packages/exo/test/test-label-instances.js @@ -4,14 +4,14 @@ import { test } from './prepare-test-env-ava-label-instances.js'; // eslint-disable-next-line import/order import { passStyleOf } from '@endo/far'; import { M } from '@endo/patterns'; + +import { q } from '@endo/errors'; import { defineExoClass, defineExoClassKit, makeExo, } from '../src/exo-makers.js'; -const { quote: q } = assert; - const UpCounterI = M.interface('UpCounter', { incr: M.call().returns(M.number()), }); diff --git a/packages/far/package.json b/packages/far/package.json index 609b471d2e..920ce96711 100644 --- a/packages/far/package.json +++ b/packages/far/package.json @@ -32,6 +32,7 @@ }, "homepage": "https://github.com/endojs/endo#readme", "dependencies": { + "@endo/errors": "^1.0.2", "@endo/eventual-send": "^1.1.0", "@endo/pass-style": "^1.1.0" }, diff --git a/packages/far/test/test-marshal-far-obj.js b/packages/far/test/test-marshal-far-obj.js index f4ecd7091f..404e3d64c4 100644 --- a/packages/far/test/test-marshal-far-obj.js +++ b/packages/far/test/test-marshal-far-obj.js @@ -1,10 +1,11 @@ // @ts-check - import { test } from './prepare-test-env-ava.js'; +// eslint-disable-next-line import/order +import { q } from '@endo/errors'; + import { Far, passStyleOf, getInterfaceOf } from '../src/index.js'; -const { quote: q } = assert; const { create, getPrototypeOf } = Object; // this only includes the tests that do not use liveSlots diff --git a/packages/import-bundle/package.json b/packages/import-bundle/package.json index cf0469af29..ef94ca706a 100644 --- a/packages/import-bundle/package.json +++ b/packages/import-bundle/package.json @@ -29,6 +29,7 @@ "dependencies": { "@endo/base64": "^1.0.1", "@endo/compartment-mapper": "^1.1.0", + "@endo/errors": "^1.0.2", "@endo/where": "^1.0.1", "ses": "^1.1.0" }, diff --git a/packages/import-bundle/src/index.js b/packages/import-bundle/src/index.js index 739e70989d..487f18a8af 100644 --- a/packages/import-bundle/src/index.js +++ b/packages/import-bundle/src/index.js @@ -7,10 +7,9 @@ import { parseArchive } from '@endo/compartment-mapper/import-archive.js'; import { decodeBase64 } from '@endo/base64'; +import { Fail } from '@endo/errors'; import { wrapInescapableCompartment } from './compartment-wrapper.js'; -const { Fail } = assert; - // importBundle takes the output of bundle-source, and returns a namespace // object (with .default, and maybe other properties for named exports) diff --git a/packages/lp32/package.json b/packages/lp32/package.json index 184152cc94..d6720b9249 100644 --- a/packages/lp32/package.json +++ b/packages/lp32/package.json @@ -49,6 +49,7 @@ "test": "ava" }, "dependencies": { + "@endo/errors": "^1.0.2", "@endo/init": "^1.0.2", "@endo/stream": "^1.0.2", "ses": "^1.1.0" diff --git a/packages/lp32/reader.js b/packages/lp32/reader.js index 13d441e760..9b0fd462ae 100644 --- a/packages/lp32/reader.js +++ b/packages/lp32/reader.js @@ -4,10 +4,9 @@ // We use a DataView to give users choice over endianness. // But DataView does not default to host-byte-order like other typed arrays. +import { Fail, q } from '@endo/errors'; import { hostIsLittleEndian } from './src/host-endian.js'; -const { Fail, quote: q } = assert; - /** * @param {Iterable | AsyncIterable} reader * @param {object} opts diff --git a/packages/lp32/writer.js b/packages/lp32/writer.js index c186c0e097..e8416cba56 100644 --- a/packages/lp32/writer.js +++ b/packages/lp32/writer.js @@ -1,10 +1,9 @@ // @ts-check /// +import { Fail, q } from '@endo/errors'; import { hostIsLittleEndian } from './src/host-endian.js'; -const { Fail, quote: q } = assert; - /** * @param {import('@endo/stream').Writer} output * @param {object} opts diff --git a/packages/marshal/package.json b/packages/marshal/package.json index d003e16105..41c1da8461 100644 --- a/packages/marshal/package.json +++ b/packages/marshal/package.json @@ -40,6 +40,7 @@ }, "homepage": "https://github.com/endojs/endo#readme", "dependencies": { + "@endo/errors": "^1.0.2", "@endo/eventual-send": "^1.1.0", "@endo/nat": "^5.0.2", "@endo/pass-style": "^1.1.0", diff --git a/packages/marshal/src/deeplyFulfilled.js b/packages/marshal/src/deeplyFulfilled.js index ebedc93a6d..e7ec72ec68 100644 --- a/packages/marshal/src/deeplyFulfilled.js +++ b/packages/marshal/src/deeplyFulfilled.js @@ -7,7 +7,8 @@ import { getTag, isObject, makeTagged, passStyleOf } from '@endo/pass-style'; /** @typedef {import('@endo/pass-style').Passable} Passable */ /** @template T @typedef {import('@endo/eventual-send').ERef} ERef */ -const { details: X, quote: q } = assert; +import { X, q } from '@endo/errors'; + const { ownKeys } = Reflect; const { fromEntries } = Object; diff --git a/packages/marshal/src/dot-membrane.js b/packages/marshal/src/dot-membrane.js index d1ad11831b..b8144d0a9f 100644 --- a/packages/marshal/src/dot-membrane.js +++ b/packages/marshal/src/dot-membrane.js @@ -3,11 +3,11 @@ import { E } from '@endo/eventual-send'; import { isObject, getInterfaceOf, Far, passStyleOf } from '@endo/pass-style'; +import { Fail } from '@endo/errors'; import { makeMarshal } from './marshal.js'; const { fromEntries } = Object; const { ownKeys } = Reflect; -const { Fail } = assert; // TODO(erights): Add Converter type /** @param {any} [mirrorConverter] */ diff --git a/packages/marshal/src/encodePassable.js b/packages/marshal/src/encodePassable.js index 877c20d297..fe24a2b0c2 100644 --- a/packages/marshal/src/encodePassable.js +++ b/packages/marshal/src/encodePassable.js @@ -18,7 +18,8 @@ import { */ /** @typedef {import('./types.js').RankCover} RankCover */ -const { quote: q, Fail } = assert; +import { q, Fail } from '@endo/errors'; + const { fromEntries, is } = Object; const { ownKeys } = Reflect; diff --git a/packages/marshal/src/encodeToCapData.js b/packages/marshal/src/encodeToCapData.js index 5546072a71..c4655d58f7 100644 --- a/packages/marshal/src/encodeToCapData.js +++ b/packages/marshal/src/encodeToCapData.js @@ -17,6 +17,7 @@ import { nameForPassableSymbol, passableSymbolForName, } from '@endo/pass-style'; +import { X, Fail, q } from '@endo/errors'; /** @typedef {import('@endo/pass-style').Passable} Passable */ /** @typedef {import('./types.js').Encoding} Encoding */ @@ -33,7 +34,6 @@ const { fromEntries, freeze, } = Object; -const { details: X, Fail, quote: q } = assert; /** * Special property name that indicates an encoding that needs special diff --git a/packages/marshal/src/encodeToSmallcaps.js b/packages/marshal/src/encodeToSmallcaps.js index 0313f6c942..ccf6f3088e 100644 --- a/packages/marshal/src/encodeToSmallcaps.js +++ b/packages/marshal/src/encodeToSmallcaps.js @@ -16,6 +16,7 @@ import { nameForPassableSymbol, passableSymbolForName, } from '@endo/pass-style'; +import { X, Fail, q } from '@endo/errors'; /** @typedef {import('@endo/pass-style').Passable} Passable */ /** @typedef {import('@endo/pass-style').Remotable} Remotable */ @@ -27,7 +28,6 @@ import { const { ownKeys } = Reflect; const { isArray } = Array; const { is, entries, fromEntries } = Object; -const { details: X, Fail, quote: q } = assert; const BANG = '!'.charCodeAt(0); const DASH = '-'.charCodeAt(0); diff --git a/packages/marshal/src/marshal-justin.js b/packages/marshal/src/marshal-justin.js index 054e689d90..240328774f 100644 --- a/packages/marshal/src/marshal-justin.js +++ b/packages/marshal/src/marshal-justin.js @@ -6,6 +6,7 @@ import { isObject, passableSymbolForName, } from '@endo/pass-style'; +import { q, X, Fail } from '@endo/errors'; import { QCLASS } from './encodeToCapData.js'; /** @typedef {import('./types.js').Encoding} Encoding */ @@ -14,7 +15,6 @@ import { QCLASS } from './encodeToCapData.js'; const { ownKeys } = Reflect; const { isArray } = Array; const { stringify: quote } = JSON; -const { quote: q, details: X, Fail } = assert; /** * @typedef {object} Indenter diff --git a/packages/marshal/src/marshal-stringify.js b/packages/marshal/src/marshal-stringify.js index 1052c90bfc..989100cda8 100644 --- a/packages/marshal/src/marshal-stringify.js +++ b/packages/marshal/src/marshal-stringify.js @@ -1,11 +1,10 @@ /// +import { Fail } from '@endo/errors'; import { makeMarshal } from './marshal.js'; /** @typedef {import('@endo/pass-style').Passable} Passable */ -const { Fail } = assert; - /** @type {import('./types.js').ConvertValToSlot} */ const doNotConvertValToSlot = val => Fail`Marshal's stringify rejects presences and promises ${val}`; diff --git a/packages/marshal/src/marshal.js b/packages/marshal/src/marshal.js index f317325ea5..11213a7536 100644 --- a/packages/marshal/src/marshal.js +++ b/packages/marshal/src/marshal.js @@ -8,6 +8,7 @@ import { hasOwnPropertyOf, } from '@endo/pass-style'; +import { X, Fail, q, makeError, errorNote } from '@endo/errors'; import { QCLASS, makeEncodeToCapData, @@ -29,7 +30,6 @@ import { /** @typedef {import('@endo/pass-style').RemotableObject} Remotable */ const { isArray } = Array; -const { details: X, Fail, quote: q } = assert; const { ownKeys } = Reflect; /** @type {ConvertValToSlot} */ @@ -124,7 +124,7 @@ export const makeMarshal = ( // with the correlation. const errorId = encodeRecur(nextErrorId()); assert.typeof(errorId, 'string'); - assert.note(err, X`Sent as ${errorId}`); + errorNote(err, X`Sent as ${errorId}`); marshalSaveError(err); return harden({ errorId, message, name }); } else { @@ -278,7 +278,7 @@ export const makeMarshal = ( dErrorId === undefined ? `Remote${EC.name}` : `Remote${EC.name}(${dErrorId})`; - const error = assert.error(dMessage, EC, { errorName }); + const error = makeError(dMessage, EC, { errorName }); return harden(error); }; diff --git a/packages/marshal/src/rankOrder.js b/packages/marshal/src/rankOrder.js index f8d8d9d95c..e11c9200f4 100644 --- a/packages/marshal/src/rankOrder.js +++ b/packages/marshal/src/rankOrder.js @@ -1,4 +1,5 @@ import { getTag, passStyleOf, nameForPassableSymbol } from '@endo/pass-style'; +import { Fail, q } from '@endo/errors'; import { passStylePrefixes, recordNames, @@ -12,7 +13,6 @@ import { /** @typedef {import('./types.js').RankCompare} RankCompare */ /** @typedef {import('./types.js').FullCompare} FullCompare */ -const { Fail, quote: q } = assert; const { entries, fromEntries, setPrototypeOf, is } = Object; /** diff --git a/packages/marshal/src/types.js b/packages/marshal/src/types.js index 47ea1fc8be..c80c1a416d 100644 --- a/packages/marshal/src/types.js +++ b/packages/marshal/src/types.js @@ -116,7 +116,7 @@ export {}; * identify the sending of errors relative to this marshal instance. * @property {(err: Error) => void=} marshalSaveError If `errorTagging` is * `'on'`, then errors serialized by this marshal instance are also - * logged by calling `marshalSaveError` *after* `assert.note` associated + * logged by calling `marshalSaveError` *after* `errorNote` associated * that error with its errorId. Thus, if `marshalSaveError` in turn logs * to the normal console, which is the default, then the console will * show that note showing the associated errorId. diff --git a/packages/marshal/test/test-encodePassable.js b/packages/marshal/test/test-encodePassable.js index 29133cc973..72495b701f 100644 --- a/packages/marshal/test/test-encodePassable.js +++ b/packages/marshal/test/test-encodePassable.js @@ -1,13 +1,15 @@ // @ts-nocheck /* eslint-disable no-bitwise, @endo/restrict-comparison-operands */ - // eslint-disable-next-line import/order import { test } from './prepare-test-env-ava.js'; -// eslint-disable-next-line import/no-extraneous-dependencies +// eslint-disable-next-line import/order import { fc } from '@fast-check/ava'; - import { arbPassable } from '@endo/pass-style/tools.js'; +import { Fail, q } from '@endo/errors'; + +// eslint-disable-next-line import/no-extraneous-dependencies + import { makeEncodePassable, makeDecodePassable, @@ -15,8 +17,6 @@ import { import { compareRank, makeComparatorKit } from '../src/rankOrder.js'; import { sample } from './test-rankOrder.js'; -const { Fail, quote: q } = assert; - const buffers = { __proto__: null, r: [], diff --git a/packages/marshal/test/test-marshal-far-obj.js b/packages/marshal/test/test-marshal-far-obj.js index a194160730..805c089288 100644 --- a/packages/marshal/test/test-marshal-far-obj.js +++ b/packages/marshal/test/test-marshal-far-obj.js @@ -1,3 +1,4 @@ +import { q } from '@endo/errors'; import { test } from './prepare-test-env-ava.js'; // eslint-disable-next-line import/order @@ -5,7 +6,6 @@ import { passStyleOf, Remotable, Far, getInterfaceOf } from '@endo/pass-style'; import { makeMarshal } from '../src/marshal.js'; -const { quote: q } = assert; const { create, getPrototypeOf, prototype: objectPrototype } = Object; // this only includes the tests that do not use liveSlots diff --git a/packages/marshal/test/test-rankOrder.js b/packages/marshal/test/test-rankOrder.js index 07392d6a16..048734b2c5 100644 --- a/packages/marshal/test/test-rankOrder.js +++ b/packages/marshal/test/test-rankOrder.js @@ -12,6 +12,7 @@ import { arbPassable, } from '@endo/pass-style/tools.js'; +import { q } from '@endo/errors'; import { FullRankCover, compareRank, @@ -22,8 +23,6 @@ import { assertRankSorted, } from '../src/rankOrder.js'; -const { quote: q } = assert; - test('compareRank is reflexive', async t => { await fc.assert( fc.property(arbPassable, x => { diff --git a/packages/pass-style/package.json b/packages/pass-style/package.json index 3c45bb38e1..88fa405c7f 100644 --- a/packages/pass-style/package.json +++ b/packages/pass-style/package.json @@ -33,6 +33,7 @@ "test": "ava" }, "dependencies": { + "@endo/errors": "^1.0.2", "@endo/eventual-send": "^1.1.0", "@endo/promise-kit": "^1.0.2", "@fast-check/ava": "^1.1.5" diff --git a/packages/pass-style/src/copyArray.js b/packages/pass-style/src/copyArray.js index 28568f8815..1a7c6d236f 100644 --- a/packages/pass-style/src/copyArray.js +++ b/packages/pass-style/src/copyArray.js @@ -1,8 +1,8 @@ /// +import { X } from '@endo/errors'; import { assertChecker, checkNormalProperty } from './passStyle-helpers.js'; -const { details: X } = assert; const { getPrototypeOf } = Object; const { ownKeys } = Reflect; const { isArray, prototype: arrayPrototype } = Array; diff --git a/packages/pass-style/src/copyRecord.js b/packages/pass-style/src/copyRecord.js index 67adc38fcf..38ee0d4ff9 100644 --- a/packages/pass-style/src/copyRecord.js +++ b/packages/pass-style/src/copyRecord.js @@ -1,12 +1,12 @@ /// +import { X } from '@endo/errors'; import { assertChecker, canBeMethod, checkNormalProperty, } from './passStyle-helpers.js'; -const { details: X } = assert; const { ownKeys } = Reflect; const { getPrototypeOf, values, prototype: objectPrototype } = Object; diff --git a/packages/pass-style/src/error.js b/packages/pass-style/src/error.js index c41e1871e6..b7798448bd 100644 --- a/packages/pass-style/src/error.js +++ b/packages/pass-style/src/error.js @@ -1,11 +1,11 @@ /// +import { X, Fail, errorNote } from '@endo/errors'; import { assertChecker } from './passStyle-helpers.js'; /** @typedef {import('./internal-types.js').PassStyleHelper} PassStyleHelper */ /** @typedef {import('./types.js').Checker} Checker */ -const { details: X, Fail } = assert; const { getPrototypeOf, getOwnPropertyDescriptors } = Object; const { ownKeys } = Reflect; @@ -116,7 +116,7 @@ export const toPassableError = err => { // Even the cleaned up error copy, if sent to the console, should // cause hidden diagnostic information of the original error // to be logged. - assert.note(newError, X`copied from error ${err}`); + errorNote(newError, X`copied from error ${err}`); return newError; }; harden(toPassableError); diff --git a/packages/pass-style/src/make-far.js b/packages/pass-style/src/make-far.js index 1e92acbbc3..2937ceba56 100644 --- a/packages/pass-style/src/make-far.js +++ b/packages/pass-style/src/make-far.js @@ -1,14 +1,13 @@ /// import { getMethodNames } from '@endo/eventual-send/utils.js'; +import { q, Fail } from '@endo/errors'; import { assertChecker, PASS_STYLE } from './passStyle-helpers.js'; import { assertIface, getInterfaceOf, RemotableHelper } from './remotable.js'; /** @typedef {import('./types.js').InterfaceSpec} InterfaceSpec */ /** @template L,R @typedef {import('@endo/eventual-send').RemotableBrand} RemotableBrand */ -const { quote: q, Fail } = assert; - const { prototype: functionPrototype } = Function; const { getPrototypeOf, diff --git a/packages/pass-style/src/makeTagged.js b/packages/pass-style/src/makeTagged.js index b20ee544b8..0a80c69106 100644 --- a/packages/pass-style/src/makeTagged.js +++ b/packages/pass-style/src/makeTagged.js @@ -1,10 +1,10 @@ /// +import { Fail } from '@endo/errors'; import { PASS_STYLE } from './passStyle-helpers.js'; import { assertPassable } from './passStyleOf.js'; const { create, prototype: objectPrototype } = Object; -const { Fail } = assert; export const makeTagged = (tag, payload) => { typeof tag === 'string' || diff --git a/packages/pass-style/src/passStyle-helpers.js b/packages/pass-style/src/passStyle-helpers.js index 840156641c..65823d35cc 100644 --- a/packages/pass-style/src/passStyle-helpers.js +++ b/packages/pass-style/src/passStyle-helpers.js @@ -3,7 +3,8 @@ /** @typedef {import('./types.js').Checker} Checker */ /** @typedef {import('./types.js').PassStyle} PassStyle */ -const { details: X, quote: q } = assert; +import { X, q } from '@endo/errors'; + const { isArray } = Array; const { prototype: functionPrototype } = Function; const { diff --git a/packages/pass-style/src/passStyleOf.js b/packages/pass-style/src/passStyleOf.js index 0a49fe71a1..a335b2bca2 100644 --- a/packages/pass-style/src/passStyleOf.js +++ b/packages/pass-style/src/passStyleOf.js @@ -3,6 +3,7 @@ /// import { isPromise } from '@endo/promise-kit'; +import { X, Fail, q } from '@endo/errors'; import { isObject, isTypedArray, PASS_STYLE } from './passStyle-helpers.js'; import { CopyArrayHelper } from './copyArray.js'; @@ -22,7 +23,6 @@ import { assertSafePromise } from './safe-promise.js'; /** @typedef {Exclude} HelperPassStyle */ -const { details: X, Fail, quote: q } = assert; const { ownKeys } = Reflect; const { isFrozen } = Object; diff --git a/packages/pass-style/src/remotable.js b/packages/pass-style/src/remotable.js index 476dff5387..0a2b32dd18 100644 --- a/packages/pass-style/src/remotable.js +++ b/packages/pass-style/src/remotable.js @@ -1,5 +1,6 @@ /// +import { X, Fail, q } from '@endo/errors'; import { assertChecker, canBeMethod, @@ -17,7 +18,6 @@ import { /** @typedef {import('./internal-types.js').PassStyleHelper} PassStyleHelper */ /** @typedef {import('./types.js').RemotableObject} Remotable */ -const { details: X, Fail, quote: q } = assert; const { ownKeys } = Reflect; const { isArray } = Array; const { diff --git a/packages/pass-style/src/safe-promise.js b/packages/pass-style/src/safe-promise.js index 30de135151..80c425d843 100644 --- a/packages/pass-style/src/safe-promise.js +++ b/packages/pass-style/src/safe-promise.js @@ -1,11 +1,11 @@ /// import { isPromise } from '@endo/promise-kit'; +import { X, q } from '@endo/errors'; import { assertChecker, hasOwnPropertyOf } from './passStyle-helpers.js'; /** @typedef {import('./types.js').Checker} Checker */ -const { details: X, quote: q } = assert; const { isFrozen, getPrototypeOf, getOwnPropertyDescriptor } = Object; const { ownKeys } = Reflect; const { toStringTag } = Symbol; diff --git a/packages/pass-style/src/symbol.js b/packages/pass-style/src/symbol.js index f67853a3bb..ca01808206 100644 --- a/packages/pass-style/src/symbol.js +++ b/packages/pass-style/src/symbol.js @@ -1,4 +1,5 @@ -const { Fail, quote: q } = assert; +import { Fail, q } from '@endo/errors'; + const { ownKeys } = Reflect; /** diff --git a/packages/pass-style/src/tagged.js b/packages/pass-style/src/tagged.js index 86cf17857b..e7d4f5bce1 100644 --- a/packages/pass-style/src/tagged.js +++ b/packages/pass-style/src/tagged.js @@ -1,5 +1,6 @@ /// +import { Fail } from '@endo/errors'; import { assertChecker, checkTagRecord, @@ -8,7 +9,6 @@ import { checkPassStyle, } from './passStyle-helpers.js'; -const { Fail } = assert; const { ownKeys } = Reflect; const { getOwnPropertyDescriptors } = Object; diff --git a/packages/pass-style/src/typeGuards.js b/packages/pass-style/src/typeGuards.js index 2d2f13e267..300c6c9486 100644 --- a/packages/pass-style/src/typeGuards.js +++ b/packages/pass-style/src/typeGuards.js @@ -1,3 +1,4 @@ +import { Fail, q } from '@endo/errors'; import { passStyleOf } from './passStyleOf.js'; /** @typedef {import('./types.js').Passable} Passable */ @@ -11,8 +12,6 @@ import { passStyleOf } from './passStyleOf.js'; */ /** @typedef {import('./types.js').RemotableObject} Remotable */ -const { Fail, quote: q } = assert; - /** * Check whether the argument is a pass-by-copy array, AKA a "copyArray" * in @endo/marshal terms diff --git a/packages/pass-style/test/test-passStyleOf.js b/packages/pass-style/test/test-passStyleOf.js index 77dd715be1..33c71a1bd9 100644 --- a/packages/pass-style/test/test-passStyleOf.js +++ b/packages/pass-style/test/test-passStyleOf.js @@ -1,12 +1,14 @@ /* eslint-disable max-classes-per-file */ import { test } from './prepare-test-env-ava.js'; +// eslint-disable-next-line import/order +import { q } from '@endo/errors'; + import { passStyleOf } from '../src/passStyleOf.js'; import { Far } from '../src/make-far.js'; import { makeTagged } from '../src/makeTagged.js'; import { PASS_STYLE } from '../src/passStyle-helpers.js'; -const { quote: q } = assert; const { getPrototypeOf, defineProperty } = Object; const { ownKeys } = Reflect; diff --git a/packages/patterns/package.json b/packages/patterns/package.json index a2bc01a610..5324eb2577 100644 --- a/packages/patterns/package.json +++ b/packages/patterns/package.json @@ -32,6 +32,7 @@ }, "dependencies": { "@endo/common": "^1.0.2", + "@endo/errors": "^1.0.2", "@endo/eventual-send": "^1.1.0", "@endo/marshal": "^1.1.0", "@endo/promise-kit": "^1.0.2" diff --git a/packages/patterns/src/keys/checkKey.js b/packages/patterns/src/keys/checkKey.js index 3fddf7022a..dc0d3f95e3 100644 --- a/packages/patterns/src/keys/checkKey.js +++ b/packages/patterns/src/keys/checkKey.js @@ -14,10 +14,10 @@ import { } from '@endo/marshal'; import { identChecker } from '@endo/common/ident-checker.js'; +import { X, q, Fail } from '@endo/errors'; import { checkElements, makeSetOfElements } from './copySet.js'; import { checkBagEntries, makeBagOfEntries } from './copyBag.js'; -const { details: X, quote: q, Fail } = assert; const { ownKeys } = Reflect; /** @typedef {import('@endo/marshal').Checker} Checker */ diff --git a/packages/patterns/src/keys/compareKeys.js b/packages/patterns/src/keys/compareKeys.js index 7beee3a65a..19a679c3cb 100644 --- a/packages/patterns/src/keys/compareKeys.js +++ b/packages/patterns/src/keys/compareKeys.js @@ -8,6 +8,7 @@ import { recordValues, trivialComparator, } from '@endo/marshal'; +import { q, Fail } from '@endo/errors'; import { assertKey, getCopyBagEntries, @@ -18,8 +19,6 @@ import { makeCompareCollection } from './keycollection-operators.js'; /** @template {import('../types.js').Key} [K=import('../types.js').Key] @typedef {import('../types').CopySet} CopySet */ -const { quote: q, Fail } = assert; - /** * CopySet X is smaller than CopySet Y iff all of these conditions hold: * 1. For every x in X, x is also in Y. diff --git a/packages/patterns/src/keys/copyBag.js b/packages/patterns/src/keys/copyBag.js index 71c897ac21..d93af49260 100644 --- a/packages/patterns/src/keys/copyBag.js +++ b/packages/patterns/src/keys/copyBag.js @@ -10,7 +10,7 @@ import { /// -const { details: X } = assert; +import { X } from '@endo/errors'; /** @template {Key} [K=Key] @typedef {import('../types').CopyBag} CopyBag */ /** @typedef {import('../types').Key} Key */ diff --git a/packages/patterns/src/keys/copySet.js b/packages/patterns/src/keys/copySet.js index e72dd65516..01137c2710 100644 --- a/packages/patterns/src/keys/copySet.js +++ b/packages/patterns/src/keys/copySet.js @@ -10,7 +10,7 @@ import { /// -const { details: X } = assert; +import { X } from '@endo/errors'; /** @template {Key} [K=Key] @typedef {import('../types').CopySet} CopySet */ /** @typedef {import('../types').Key} Key */ diff --git a/packages/patterns/src/keys/keycollection-operators.js b/packages/patterns/src/keys/keycollection-operators.js index e738188986..e55b3a31a9 100644 --- a/packages/patterns/src/keys/keycollection-operators.js +++ b/packages/patterns/src/keys/keycollection-operators.js @@ -14,7 +14,7 @@ import { makeArrayIterator } from '@endo/common/make-array-iterator.js'; /** @typedef {import('../types').FullCompare} FullCompare */ /** @typedef {import('../types').KeyCollection} KeyCollection */ -const { quote: q, Fail } = assert; +import { q, Fail } from '@endo/errors'; /** * Refines a sequence of entries that is already sorted over its keys by the diff --git a/packages/patterns/src/keys/merge-bag-operators.js b/packages/patterns/src/keys/merge-bag-operators.js index 88a1ce1e50..04dcfa2039 100644 --- a/packages/patterns/src/keys/merge-bag-operators.js +++ b/packages/patterns/src/keys/merge-bag-operators.js @@ -4,10 +4,9 @@ import { makeFullOrderComparatorKit, sortByRank, } from '@endo/marshal'; +import { q, Fail } from '@endo/errors'; import { assertNoDuplicateKeys, makeBagOfEntries } from './copyBag.js'; -const { quote: q, Fail } = assert; - /** @typedef {import('../types').KeyComparison} KeyComparison */ /** @typedef {import('../types').FullCompare} FullCompare */ /** @typedef {import('@endo/marshal').RankCompare} RankCompare */ diff --git a/packages/patterns/src/keys/merge-set-operators.js b/packages/patterns/src/keys/merge-set-operators.js index c18e18d070..42351b180d 100644 --- a/packages/patterns/src/keys/merge-set-operators.js +++ b/packages/patterns/src/keys/merge-set-operators.js @@ -4,10 +4,9 @@ import { makeFullOrderComparatorKit, sortByRank, } from '@endo/marshal'; +import { q, Fail } from '@endo/errors'; import { assertNoDuplicates, makeSetOfElements } from './copySet.js'; -const { quote: q, Fail } = assert; - /** @typedef {import('../types').KeyComparison} KeyComparison */ /** @typedef {import('../types').FullCompare} FullCompare */ /** @typedef {import('@endo/marshal').RankCompare} RankCompare */ diff --git a/packages/patterns/src/patterns/patternMatchers.js b/packages/patterns/src/patterns/patternMatchers.js index 55bb8de11b..2cfb1f3d89 100644 --- a/packages/patterns/src/patterns/patternMatchers.js +++ b/packages/patterns/src/patterns/patternMatchers.js @@ -18,6 +18,7 @@ import { applyLabelingError } from '@endo/common/apply-labeling-error.js'; import { fromUniqueEntries } from '@endo/common/from-unique-entries.js'; import { listDifference } from '@endo/common/list-difference.js'; +import { q, b, X, Fail, makeError, errorNote } from '@endo/errors'; import { keyEQ, keyGT, keyGTE, keyLT, keyLTE } from '../keys/compareKeys.js'; import { assertKey, @@ -36,7 +37,6 @@ import { generateCollectionPairEntries } from '../keys/keycollection-operators.j /// -const { quote: q, bare: b, details: X, Fail } = assert; const { entries, values } = Object; const { ownKeys } = Reflect; @@ -586,11 +586,11 @@ const makePatternKit = () => { } // should only throw checkMatches(specimen, patt, assertChecker, label); - const outerError = assert.error( + const outerError = makeError( X`internal: ${label}: inconsistent pattern match: ${q(patt)}`, ); if (innerError !== undefined) { - assert.note(outerError, X`caused by ${innerError}`); + errorNote(outerError, X`caused by ${innerError}`); } throw outerError; }; diff --git a/packages/patterns/test/test-copyMap.js b/packages/patterns/test/test-copyMap.js index 151ed195b1..feb27aa540 100644 --- a/packages/patterns/test/test-copyMap.js +++ b/packages/patterns/test/test-copyMap.js @@ -1,5 +1,7 @@ -import { test } from './prepare-test-env-ava.js'; // eslint-disable-next-line import/order +import { test } from './prepare-test-env-ava.js'; + +import { Fail } from '@endo/errors'; import { makeTagged, getTag, passStyleOf } from '@endo/marshal'; import { isCopyMap, @@ -12,8 +14,6 @@ import { matches } from '../src/patterns/patternMatchers.js'; import '../src/types.js'; -const { Fail } = assert; - const assertIsCopyMap = (t, m) => { t.is(passStyleOf(m), 'tagged'); t.is(getTag(m), 'copyMap'); diff --git a/packages/patterns/test/test-patterns.js b/packages/patterns/test/test-patterns.js index 60a9891da1..65f21dd7d7 100644 --- a/packages/patterns/test/test-patterns.js +++ b/packages/patterns/test/test-patterns.js @@ -1,6 +1,8 @@ /* eslint-disable no-continue */ -import { test } from './prepare-test-env-ava.js'; // eslint-disable-next-line import/order +import { test } from './prepare-test-env-ava.js'; + +import { Fail } from '@endo/errors'; import { makeTagged, Far } from '@endo/marshal'; import { makeCopyBag, @@ -13,8 +15,6 @@ import '../src/types.js'; /** @typedef {import('ava').ExecutionContext} TestContext */ -const { Fail } = assert; - // TODO The desired semantics for CopyMap comparison have not yet been decided. // See https://github.com/endojs/endo/pull/1737#pullrequestreview-1596595411 const copyMapComparison = (() => { diff --git a/packages/stream-node/package.json b/packages/stream-node/package.json index b0483271cc..b14de7695c 100644 --- a/packages/stream-node/package.json +++ b/packages/stream-node/package.json @@ -40,6 +40,7 @@ "test": "ava" }, "dependencies": { + "@endo/errors": "^1.0.2", "@endo/init": "^1.0.2", "@endo/stream": "^1.0.2", "ses": "^1.1.0" diff --git a/packages/stream-node/reader.js b/packages/stream-node/reader.js index c4c2947fec..0b232ef1e5 100644 --- a/packages/stream-node/reader.js +++ b/packages/stream-node/reader.js @@ -8,7 +8,7 @@ import { mapReader } from '@endo/stream'; -const { Fail, quote: q } = assert; +import { Fail, q } from '@endo/errors'; /** * @param {import('stream').Readable} input the source Node.js reader diff --git a/packages/stream-node/writer.js b/packages/stream-node/writer.js index 2c9d27d069..59f8038e45 100644 --- a/packages/stream-node/writer.js +++ b/packages/stream-node/writer.js @@ -5,7 +5,7 @@ // @ts-check /// -const { Fail } = assert; +import { Fail } from '@endo/errors'; const sink = harden(() => {});