Skip to content

Commit

Permalink
fix(ses): Support absence of console
Browse files Browse the repository at this point in the history
Fix #1819
  • Loading branch information
gibson042 committed Oct 12, 2023
1 parent 383046e commit fece445
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
4 changes: 4 additions & 0 deletions packages/ses/src/error/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ freeze(ErrorInfo);

/** @type {MakeCausalConsole} */
const makeCausalConsole = (baseConsole, loggedErrorHandler) => {
if (!baseConsole) {
return undefined;
}

const { getStackString, tagError, takeMessageLogArgs, takeNoteLogArgsArray } =
loggedErrorHandler;

Expand Down
4 changes: 2 additions & 2 deletions packages/ses/src/error/internal-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
* calls methods of the `loggedErrorHandler` to customize how it handles logged
* errors.
*
* @param {VirtualConsole} baseConsole
* @param {VirtualConsole | undefined} baseConsole
* @param {LoggedErrorHandler} loggedErrorHandler
* @returns {VirtualConsole}
* @returns {VirtualConsole | undefined}
*/
11 changes: 8 additions & 3 deletions packages/ses/src/error/tame-console.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import './types.js';
import './internal-types.js';

// eslint-disable-next-line no-restricted-globals
const originalConsole = console;
const originalConsole = /** @type {VirtualConsole} */ (
typeof console !== 'undefined'
? console
: undefined
);

/**
* Wrap console unless suppressed.
Expand Down Expand Up @@ -40,10 +44,11 @@ export const tameConsole = (
getStackString: optGetStackString,
};
}
const ourConsole =
const ourConsole = /** @type {VirtualConsole} */ (
consoleTaming === 'unsafe'
? originalConsole
: makeCausalConsole(originalConsole, loggedErrorHandler);
: makeCausalConsole(originalConsole, loggedErrorHandler)
);

// Attach platform-specific error traps such that any error that gets thrown
// at top-of-turn (the bottom of stack) will get logged by our causal
Expand Down

0 comments on commit fece445

Please sign in to comment.