From 1385a6ce97f8a7657e555f17cf60f1ab01904dda Mon Sep 17 00:00:00 2001 From: "Mark S. Miller" Date: Mon, 13 Jan 2025 13:10:33 -0800 Subject: [PATCH] feat(ses): can breakpoint or log on assert failures --- packages/ses/src/error/assert.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/packages/ses/src/error/assert.js b/packages/ses/src/error/assert.js index f4a645c5b0..82fe46484c 100644 --- a/packages/ses/src/error/assert.js +++ b/packages/ses/src/error/assert.js @@ -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, @@ -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) @@ -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);