Skip to content

Commit

Permalink
refactor(internal): remove unused functions migrating to endo (Agoric…
Browse files Browse the repository at this point in the history
…#8723)

Co-authored-by: Mathieu Hofman <86499+mhofman@users.noreply.github.com>
  • Loading branch information
erights and mhofman authored Jan 9, 2024
1 parent 780a461 commit 4dcc411
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 80 deletions.
13 changes: 0 additions & 13 deletions packages/assert/src/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,3 @@ function an(str) {
}
freeze(an);
export { an };

/**
* In the `assertFoo`/`isFoo`/`checkFoo` pattern, `checkFoo` has a `check`
* parameter of type `Checker`. `assertFoo` calls `checkFoo` passes
* `assertChecker` as the `check` argument. `isFoo` passes `identChecker`
* as the `check` argument. `identChecker` acts precisely like an
* identity function, but is typed as a `Checker` to indicate its
* intended use.
*
* @type {Checker}
*/
export const identChecker = (cond, _details) => cond;
harden(identChecker);
69 changes: 2 additions & 67 deletions packages/internal/src/utils.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
// @ts-check
// @jessie-check

import { E } from '@endo/far';
import { deeplyFulfilled, isObject } from '@endo/marshal';
import { isPromise, makePromiseKit } from '@endo/promise-kit';
import { makePromiseKit } from '@endo/promise-kit';
import { makeQueue } from '@endo/stream';
import { asyncGenerate, makeSet } from 'jessie.js';

const { fromEntries, keys, values } = Object;
const { ownKeys } = Reflect;

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

export const BASIS_POINTS = 10_000n;

Expand Down Expand Up @@ -44,70 +43,6 @@ harden(fromUniqueEntries);

export { objectMap } from '@endo/patterns';

/**
* @param {Array<string | symbol>} leftNames
* @param {Array<string | symbol>} rightNames
*/
export const listDifference = (leftNames, rightNames) => {
const rightSet = makeSet(rightNames);
return leftNames.filter(name => !rightSet.has(name));
};
harden(listDifference);

/**
* @param {Error} innerErr
* @param {string|number} label
* @param {ErrorConstructor} [ErrorConstructor]
* @returns {never}
*/
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}`);
throw outerErr;
};
harden(throwLabeled);

/**
* @template A,R
* @param {(...args: A[]) => R} func
* @param {A[]} args
* @param {string|number} [label]
* @returns {R}
*/
export const applyLabelingError = (func, args, label = undefined) => {
if (label === undefined) {
return func(...args);
}
let result;
try {
result = func(...args);
} catch (err) {
throwLabeled(err, label);
}
if (isPromise(result)) {
// If result is a rejected promise, this will return a promise with a
// different rejection reason. But this confuses TypeScript because it types
// that case as `Promise<never>` which is cool for a promise that will never
// fulfill. But TypeScript doesn't understand that this will only happen
// when `result` was a rejected promise. In only this case `R` should
// already allow `Promise<never>` as a subtype.
/** @type {unknown} */
const relabeled = E.when(result, undefined, reason =>
throwLabeled(reason, label),
);
return /** @type {R} */ (relabeled);
} else {
return result;
}
};
harden(applyLabelingError);

/**
* @template T
* @typedef {{[KeyType in keyof T]: T[KeyType]} & {}} Simplify
Expand Down

0 comments on commit 4dcc411

Please sign in to comment.