Skip to content

Commit

Permalink
refactor: use @endo/errors (#9513)
Browse files Browse the repository at this point in the history
Staged on #9514

closes: #5672
refs: #8332 #9512 #9514

Some description text below copied from #8332

## Description

Use the new `@endo/errors` and retire `@agoric/assert`.

This deletes the `@agoric/assert` package but doesn't so far as to deprecate it in NPM.

Fixes #5672 -- migrating all applicable uses of `assert` to import it from @endo/errors and use that one. This is a fresh attempt to do over what #8332 and #9512 tried to do.

Note that this is staged on #9514 which addresses #9515 -- ensuring that the `assert` used in endowing a new compartment is not the `assert` imported from @endo/errors but is rather the original `globalThis.assert`. For the agoric-sdk repo, that should be the only needed use of `assert` that should not be changed to use the one imported from @endo/errors.

### Security Considerations

Relies more directly on Endo, instead of through the `assert` package.

### Scaling Considerations
none

### Documentation Considerations
we should generally document @endo/errors as the only source of `assert`. However, we still need to call out the special case of Compartment endowments covered by #9514 and #9515 

### Testing Considerations

If CI passes here, it not only tests the correctness of this PR, but also of #9514, since #9514 by itself does not cause any testable changes. It is only to enable the changes in this PR to work.

### Upgrade Considerations

TBD. `@endo/errors` may require a newer SES than the vats have in their global env (for the `assert` global).
  • Loading branch information
erights authored Jul 3, 2024
1 parent 0705f2c commit 940d3f0
Show file tree
Hide file tree
Showing 483 changed files with 705 additions and 1,879 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/test-all-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,6 @@ jobs:
- name: yarn test (access-token)
if: (success() || failure())
run: cd packages/access-token && yarn ${{ steps.vars.outputs.test }} | $TEST_COLLECT
- name: yarn test (assert)
if: (success() || failure())
run: cd packages/assert && yarn ${{ steps.vars.outputs.test }} | $TEST_COLLECT
- name: yarn test (benchmark)
if: (success() || failure())
run: cd packages/benchmark && yarn ${{ steps.vars.outputs.test }} | $TEST_COLLECT
Expand Down
2 changes: 1 addition & 1 deletion a3p-integration/proposals/c:stake-bld/test-lib/rpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
// @ts-check
/* global Buffer */

import { Fail } from '@endo/errors';
import {
boardSlottingMarshaller,
makeBoardRemote,
} from '@agoric/internal/src/marshal.js';
import { Fail } from '@endo/errors';

export { boardSlottingMarshaller };

Expand Down
2 changes: 1 addition & 1 deletion multichain-testing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
"packageManager": "yarn@4.1.1",
"devDependencies": {
"@agoric/assert": "^0.6.0",
"@endo/errors": "^1.2.2",
"@agoric/cosmic-proto": "0.4.1-dev-08f8549.0",
"@cosmjs/crypto": "^0.32.2",
"@cosmjs/proto-signing": "^0.32.2",
Expand Down
2 changes: 1 addition & 1 deletion multichain-testing/tools/batchQuery.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assert } from '@agoric/assert';
import { assert } from '@endo/errors';
import { E } from '@endo/far';

/** @typedef {'children' | 'data'} AgoricChainStoragePathKind */
Expand Down
2 changes: 1 addition & 1 deletion multichain-testing/tools/e2e-tools.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** global harden */
import { assert } from '@agoric/assert';
import { assert } from '@endo/errors';
import { E, Far } from '@endo/far';
import { Nat } from '@endo/nat';
import { makePromiseKit } from '@endo/promise-kit';
Expand Down
2 changes: 1 addition & 1 deletion multichain-testing/tools/makeHttpClient.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assert } from '@agoric/assert';
import { assert } from '@endo/errors';
import { Far } from '@endo/far';

const { freeze } = Object;
Expand Down
2 changes: 1 addition & 1 deletion packages/ERTP/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
},
"homepage": "https://github.com/Agoric/agoric-sdk#readme",
"dependencies": {
"@agoric/assert": "^0.6.0",
"@endo/errors": "^1.2.2",
"@agoric/notifier": "^0.6.2",
"@agoric/store": "^0.9.2",
"@agoric/vat-data": "^0.5.2",
Expand Down
3 changes: 1 addition & 2 deletions packages/ERTP/src/amountMath.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { q, Fail } from '@endo/errors';
import { passStyleOf, assertRemotable, assertRecord } from '@endo/marshal';

import { M, matches } from '@agoric/store';
Expand All @@ -11,8 +12,6 @@ import { copyBagMathHelpers } from './mathHelpers/copyBagMathHelpers.js';
* @import {Amount, AssetKind, AmountValue, AssetKindForValue, AssetValueForKind, Brand, CopyBagAmount, CopySetAmount, MathHelpers, NatAmount, NatValue, SetAmount, SetValue} from './types.js';
*/

const { quote: q, Fail } = assert;

/**
* Constants for the kinds of assets we support.
*
Expand Down
2 changes: 1 addition & 1 deletion packages/ERTP/src/displayInfo.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @jessie-check

import { Fail } from '@agoric/assert';
import { Fail } from '@endo/errors';
import { mustMatch } from '@agoric/store';

import { DisplayInfoShape } from './typeGuards.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/ERTP/src/issuerKit.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @jessie-check

import { assert, Fail } from '@agoric/assert';
import { assert, Fail } from '@endo/errors';
import { assertPattern } from '@agoric/store';
import { makeScalarBigMapStore } from '@agoric/vat-data';
import { makeDurableZone } from '@agoric/zone/durable.js';
Expand Down
5 changes: 2 additions & 3 deletions packages/ERTP/src/legacy-payment-helpers.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
// @jessie-check

import { mustMatch } from '@agoric/store';
import { Fail } from '@endo/errors';
import { E } from '@endo/far';
import { mustMatch } from '@agoric/store';
import { AmountMath } from './amountMath.js';

/**
* @import {ERef} from '@endo/far');
* @import {Amount, AssetKind, AmountValue, AssetKindForValue, Payment, Brand, Purse} from './types.js'
*/

const { Fail } = assert;

/**
* @file This file contains safer helper function alternatives to the similarly
* named methods on issuer. These are parameterized by a purse used for
Expand Down
2 changes: 1 addition & 1 deletion packages/ERTP/src/mathHelpers/natMathHelpers.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// @jessie-check

import { Fail } from '@endo/errors';
import { Nat, isNat } from '@endo/nat';

/** @import {MathHelpers, NatValue} from '../types.js' */

const { Fail } = assert;
const empty = 0n;

/**
Expand Down
5 changes: 2 additions & 3 deletions packages/ERTP/src/paymentLedger.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/// <reference types="@agoric/store/exported.js" />

/* eslint-disable no-use-before-define */
import { X, q, Fail, annotateError } from '@endo/errors';
import { isPromise } from '@endo/promise-kit';
import { mustMatch, M, keyEQ } from '@agoric/store';
import { AmountMath } from './amountMath.js';
Expand All @@ -17,8 +18,6 @@ import { BrandI, makeIssuerInterfaces } from './typeGuards.js';
* @import {Key} from '@endo/patterns';
*/

const { details: X, quote: q, Fail } = assert;

/**
* @param {Brand} brand
* @param {AssetKind} assetKind
Expand Down Expand Up @@ -133,7 +132,7 @@ export const preparePaymentLedger = (
try {
optShutdownWithFailure(reason);
} catch (errInShutdown) {
assert.note(errInShutdown, X`Caused by: ${reason}`);
annotateError(errInShutdown, X`Caused by: ${reason}`);
throw errInShutdown;
}
}
Expand Down
3 changes: 1 addition & 2 deletions packages/ERTP/src/purse.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { Fail } from '@endo/errors';
import { M, makeCopySet } from '@agoric/store';
import { AmountMath } from './amountMath.js';
import { makeTransientNotifierKit } from './transientNotifier.js';
import { makeAmountStore } from './amountStore.js';

/** @import {Amount, AssetKind, AmountValue, AssetKindForValue, RecoverySetsOption, Brand, Payment} from './types.js' */

const { Fail } = assert;

const EMPTY_COPY_SET = makeCopySet([]);

// TODO Type InterfaceGuard better than InterfaceGuard<any>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { E } from '@endo/eventual-send';
import { assert, details as X } from '@agoric/assert';
import { assert, X } from '@endo/errors';
import { Far } from '@endo/marshal';
import { makeIssuerKit, AmountMath } from '../../../src/index.js';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test } from '@agoric/swingset-vat/tools/prepare-test-env-ava.js';

import { assert } from '@agoric/assert';
import { assert } from '@endo/errors';
import { buildVatController } from '@agoric/swingset-vat';

const bfile = name => new URL(name, import.meta.url).pathname;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { E } from '@endo/eventual-send';
import { assert, details as X } from '@agoric/assert';
import { assert, X } from '@endo/errors';
import { Far } from '@endo/marshal';
import { makeIssuerKit, AmountMath } from '../../../src/index.js';

Expand Down
2 changes: 1 addition & 1 deletion packages/ERTP/test/unitTests/mintObj.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test } from '@agoric/swingset-vat/tools/prepare-test-env-ava.js';

import { assert } from '@endo/errors';
import { initEmpty, M } from '@agoric/store';
import { assert } from '@agoric/assert';

import { defineDurableKind, makeKindHandle } from '@agoric/vat-data';
import { makeIssuerKit, AssetKind, AmountMath } from '../../src/index.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@types/yargs-parser": "^21.0.0"
},
"dependencies": {
"@agoric/assert": "^0.6.0",
"@endo/errors": "^1.2.2",
"@agoric/internal": "^0.3.2",
"@agoric/kmarshal": "^0.1.0",
"@agoric/store": "^0.9.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/src/controller/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { tmpName } from 'tmp';
import anylogger from 'anylogger';
import microtime from 'microtime';

import { assert, Fail } from '@agoric/assert';
import { assert, Fail } from '@endo/errors';
import { importBundle } from '@endo/import-bundle';
import { initSwingStore } from '@agoric/swing-store';

Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/src/controller/initializeKernel.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-disable no-use-before-define */

import { assert, Fail } from '@endo/errors';
import { makeMarshal } from '@endo/marshal';
import { Far } from '@endo/far';
import { assert, Fail } from '@agoric/assert';
import { kser, kunser } from '@agoric/kmarshal';
import { assertKnownOptions } from '../lib/assertOptions.js';
import { insistVatID } from '../lib/id.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/src/controller/initializeSwingset.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import fs from 'fs';
import path from 'path';

import { assert, Fail } from '@agoric/assert';
import { assert, Fail } from '@endo/errors';
import { makeTracer } from '@agoric/internal';
import { mustMatch } from '@agoric/store';
import bundleSource from '@endo/bundle-source';
Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/src/controller/startXSnap.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from 'path';
import { Fail } from '@agoric/assert';
import { Fail } from '@endo/errors';
import { type as osType } from 'os';
import { xsnap, recordXSnap } from '@agoric/xsnap';

Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/src/devices/bridge/device-bridge.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Fail } from '@agoric/assert';
import { Fail } from '@endo/errors';
import { Far } from '@endo/far';

function sanitize(data) {
Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/src/devices/bundle/device-bundle.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assert } from '@agoric/assert';
import { assert } from '@endo/errors';
import { buildSerializationTools } from '../lib/deviceTools.js';

/*
Expand Down
3 changes: 1 addition & 2 deletions packages/SwingSet/src/devices/command/command.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Fail } from '@endo/errors';
import { makePromiseKit } from '@endo/promise-kit';
import { Nat } from '@endo/nat';

import { Fail } from '@agoric/assert';

export default function buildCommand(broadcastCallback) {
broadcastCallback || Fail`broadcastCallback must be provided.`;
let inboundCallback;
Expand Down
3 changes: 1 addition & 2 deletions packages/SwingSet/src/devices/command/device-command.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Fail } from '@endo/errors';
import { Nat } from '@endo/nat';
import { Far } from '@endo/far';

import { Fail } from '@agoric/assert';

export function buildRootDeviceNode(tools) {
const { SO, getDeviceState, setDeviceState, endowments } = tools;
const { registerInboundCallback, deliverResponse, sendBroadcast } =
Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/src/devices/lib/deviceTools.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assert, Fail } from '@agoric/assert';
import { assert, Fail } from '@endo/errors';
import { makeMarshal } from '@endo/marshal';
import { Far } from '@endo/far';
import { parseVatSlot } from '../../lib/parseVatSlots.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/src/devices/loopbox/device-loopbox.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Fail } from '@agoric/assert';
import { Fail } from '@endo/errors';
import { Far } from '@endo/far';

export function buildRootDeviceNode(tools) {
Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/src/devices/loopbox/loopbox.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Fail } from '@agoric/assert';
import { Fail } from '@endo/errors';

/*
* The "loopbox" is a special device used for unit tests, which glues one
Expand Down
3 changes: 1 addition & 2 deletions packages/SwingSet/src/devices/mailbox/device-mailbox.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { assert, Fail } from '@endo/errors';
import { Nat } from '@endo/nat';
import { Far } from '@endo/far';

import { assert, Fail } from '@agoric/assert';

export function buildRootDeviceNode(tools) {
const { SO, getDeviceState, setDeviceState, endowments } = tools;

Expand Down
3 changes: 1 addition & 2 deletions packages/SwingSet/src/devices/mailbox/mailbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,9 @@
*/

import { Fail } from '@endo/errors';
import { Nat } from '@endo/nat';

import { Fail } from '@agoric/assert';

// This Map-based mailboxState object is a good starting point, but we may
// replace it with one that tracks which parts of the state have been
// modified, to build more efficient Merkle proofs.
Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/src/devices/plugin/device-plugin.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Fail } from '@endo/errors';
import { makeCapTP } from '@endo/captp';
import { Far } from '@endo/far';
import { Fail } from '@agoric/assert';

export function buildRootDeviceNode(tools) {
const { SO, getDeviceState, setDeviceState, endowments } = tools;
Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/src/devices/timer/device-timer.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/

import { Nat } from '@endo/nat';
import { assert, Fail } from '@agoric/assert';
import { assert, Fail } from '@endo/errors';
import { Far } from '@endo/far';

// Since we use harden when saving the state, we need to copy the arrays so they
Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/src/devices/timer/timer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Nat } from '@endo/nat';

import { Fail } from '@agoric/assert';
import { Fail } from '@endo/errors';

/**
* Endowments for a Timer device that can be made available to SwingSet vats.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Nat } from '@endo/nat';
import { assert } from '@agoric/assert';
import { assert } from '@endo/errors';
import { kunser } from '@agoric/kmarshal';
import { buildSerializationTools } from '../lib/deviceTools.js';
import { insistVatID } from '../../lib/id.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/src/kernel/deviceManager.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assert, Fail } from '@agoric/assert';
import { assert, Fail } from '@endo/errors';
import { makeDeviceSlots } from './deviceSlots.js';
import { insistCapData } from '../lib/capdata.js';

Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/src/kernel/deviceSlots.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Remotable, makeMarshal } from '@endo/marshal';
import { passStyleOf } from '@endo/far';
import { assert, Fail } from '@agoric/assert';
import { assert, Fail } from '@endo/errors';
import {
insistVatType,
makeVatSlot,
Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/src/kernel/deviceTranslator.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @ts-nocheck
import { assert, Fail } from '@agoric/assert';
import { assert, Fail } from '@endo/errors';
import { insistMessage } from '../lib/message.js';
import { insistKernelType } from './parseKernelSlots.js';
import { insistVatType, parseVatSlot } from '../lib/parseVatSlots.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/src/kernel/dummyMeterControl.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assert } from '@agoric/assert';
import { assert } from '@endo/errors';

export function makeDummyMeterControl() {
let meteringDisabled = 0;
Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/src/kernel/gc-actions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Fail } from '@agoric/assert';
import { Fail } from '@endo/errors';
import { insistKernelType } from './parseKernelSlots.js';
import { insistVatID } from '../lib/id.js';

Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/src/kernel/kernel.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* global globalThis */

import { assert, Fail } from '@agoric/assert';
import { assert, Fail } from '@endo/errors';
import { isNat } from '@endo/nat';
import { importBundle } from '@endo/import-bundle';
import { makeUpgradeDisconnection } from '@agoric/internal/src/upgrade-api.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/src/kernel/kernelSyscall.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assert, Fail } from '@agoric/assert';
import { assert, Fail } from '@endo/errors';
import { insistKernelType } from './parseKernelSlots.js';
import { insistCapData } from '../lib/capdata.js';
import { insistDeviceID, insistVatID } from '../lib/id.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/src/kernel/parseKernelSlots.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Nat } from '@endo/nat';
import { assert, Fail } from '@agoric/assert';
import { assert, Fail } from '@endo/errors';

// Object/promise references (in the kernel) contain a two-tuple of (type,
// index). All object references point to entries in the kernel Object
Expand Down
Loading

0 comments on commit 940d3f0

Please sign in to comment.