@metamask/ocap-kernel
Version:
OCap kernel core components
1 lines • 2.55 kB
Source Map (JSON)
{"version":3,"file":"assert.mjs","sourceRoot":"","sources":["../../src/utils/assert.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,gFAAgF;AAChF,8EAA8E;AAC9E,+EAA+E;AAC/E,6EAA6E;AAC7E,gFAAgF;AAChF,8DAA8D;AAC9D,EAAE;AACF,oBAAoB;AACpB,EAAE;AACF,KAAK;AACL,EAAE;AACF,0BAA0B;AAC1B,EAAE;AACF,+EAA+E;AAC/E,+EAA+E;AAC/E,4EAA4E;AAC5E,8EAA8E;AAC9E,+EAA+E;AAC/E,gBAAgB;AAChB,EAAE;AACF,8EAA8E;AAC9E,gFAAgF;AAChF,uBAAuB;AAEvB,2EAA2E;AAC3E,4EAA4E;AAC5E,aAAa;AAEb,OAAO,EAAE,MAAM,EAAE,IAAI,IAAI,0BAA0B,EAAE,qBAAqB;AAE1E,OAAO,EAAE,MAAM,EAAE,CAAC;AAElB,4EAA4E;AAC5E,4EAA4E;AAC5E,yCAAyC;AACzC,MAAM,CAAC,MAAM,IAAI,GAAG,CAClB,OAA6B,EAC7B,GAAG,MAAiB,EACb,EAAE,CAAC,0BAA0B,CAAC,OAAO,EAAE,GAAG,MAAM,CAAC,CAAC","sourcesContent":["// Importing from this module substitutes for importing from the @endo/errors\n// package. Bugs in the TypeScript compiler's control flow analysis cause it to\n// make incorrect inferences about the behavior of the `Fail` function, as the\n// compiler currently handles the `never` return type incorrectly. We can work\n// around the problems this introduces by speaking a falsehood about `Fail`'s\n// return type, so that control flow terminations that should have been detected\n// but weren't can be reestablished by rewriting occurances of\n//\n// Fail`whatever`;\n//\n// as\n//\n// throw Fail`whatever`;\n//\n// If we do this using `Fail` out of the box, it will trip over the eslint rule\n// that requires things that are thrown to be Errors, which, of course, `never`\n// is not. However, what `Fail` does is throw an Error, so the spirit of the\n// rule is maintained, i.e., the consequence of `throw Fail...` is to throw an\n// Error, even though it's not actually the throw statement itself that's doing\n// the throwing.\n//\n// This is a ugly hack, which we hope to retire just as soon as the TypeScript\n// team fixes the type analysis bug in tsc. However, we don't know when or even\n// if that will happen.\n\n// Note: currently, the only things from `@endo/errors` we actually use are\n// `assert` and `Fail`. If we add to that list, those should be incorporated\n// here also.\n\nimport { assert, Fail as failThatConfusesTypeScript } from '@endo/errors';\n\nexport { assert };\n\n// This is simply proxying the normal `Fail`, while substituting a different\n// declared return type. It costs an extra level of function call, but this\n// cost is only paid in the failure case.\nexport const Fail = (\n strings: TemplateStringsArray,\n ...values: unknown[]\n): Error => failThatConfusesTypeScript(strings, ...values);\n"]}