@metamask/ocap-kernel
Version:
OCap kernel core components
38 lines • 1.97 kB
JavaScript
;
// Importing from this module substitutes for importing from the @endo/errors
// package. Bugs in the TypeScript compiler's control flow analysis cause it to
// make incorrect inferences about the behavior of the `Fail` function, as the
// compiler currently handles the `never` return type incorrectly. We can work
// around the problems this introduces by speaking a falsehood about `Fail`'s
// return type, so that control flow terminations that should have been detected
// but weren't can be reestablished by rewriting occurances of
//
// Fail`whatever`;
//
// as
//
// throw Fail`whatever`;
//
// If we do this using `Fail` out of the box, it will trip over the eslint rule
// that requires things that are thrown to be Errors, which, of course, `never`
// is not. However, what `Fail` does is throw an Error, so the spirit of the
// rule is maintained, i.e., the consequence of `throw Fail...` is to throw an
// Error, even though it's not actually the throw statement itself that's doing
// the throwing.
//
// This is a ugly hack, which we hope to retire just as soon as the TypeScript
// team fixes the type analysis bug in tsc. However, we don't know when or even
// if that will happen.
Object.defineProperty(exports, "__esModule", { value: true });
exports.Fail = exports.assert = void 0;
// Note: currently, the only things from `@endo/errors` we actually use are
// `assert` and `Fail`. If we add to that list, those should be incorporated
// here also.
const errors_1 = require("@endo/errors");
Object.defineProperty(exports, "assert", { enumerable: true, get: function () { return errors_1.assert; } });
// This is simply proxying the normal `Fail`, while substituting a different
// declared return type. It costs an extra level of function call, but this
// cost is only paid in the failure case.
const Fail = (strings, ...values) => (0, errors_1.Fail)(strings, ...values);
exports.Fail = Fail;
//# sourceMappingURL=assert.cjs.map