Skip to content

Commit

Permalink
feat(ses): can breakpoint or log on assert failures
Browse files Browse the repository at this point in the history
  • Loading branch information
erights committed Jan 17, 2025
1 parent 630592d commit 1385a6c
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions packages/ses/src/error/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// of `console.js`. However, for code that does not have such access, this
// module should not be observably impure.

import { getEnvironmentOption as getenv } from '@endo/env-options';
import {
RangeError,
TypeError,
Expand Down Expand Up @@ -269,7 +270,7 @@ const tagError = (err, optErrorName = err.name) => {
* such as `stack` on v8 (Chrome, Brave, Edge?)
* - `sanitizeError` will freeze the error, preventing any correct engine from
* adding or
* altering any of the error's own properties `sanitizeError` is done.
* altering any of the error's own properties once `sanitizeError` is done.
*
* However, `sanitizeError` will not, for example, `harden`
* (i.e., deeply freeze)
Expand Down Expand Up @@ -369,7 +370,23 @@ const makeError = (
if (sanitize) {
sanitizeError(error);
}
// The next line is a particularly fruitful place to put a breakpoint.
// We assume creating an error means we're already on the slow path
// so we can afford to check the environment variable again. We
// check it each time so that it could be modified by something else,
// affecting behavior here.
const viewAssertError = getenv('SES_VIEW_ASSERT_ERROR', 'none', [
'breakpoint',
'log',
]);
if (viewAssertError !== 'none') {
if (viewAssertError === 'breakpoint') {
// eslint-disable-next-line no-debugger
debugger;
} else if (viewAssertError === 'log') {
// eslint-disable-next-line @endo/no-polymorphic-call
console.log(error);
}
}
return error;
};
freeze(makeError);
Expand Down

0 comments on commit 1385a6c

Please sign in to comment.