Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ses): can breakpoint or log on assert failures #2689

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading