Skip to content

Commit

Permalink
style(ses): DRY out a failFast helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
gibson042 committed Jan 8, 2024
1 parent 5d637d0 commit 08cbae5
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions packages/ses/src/error/tame-console.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import { makeRejectionHandlers } from './unhandled-rejection.js';
import './types.js';
import './internal-types.js';

const failFast = message => {
throw TypeError(message);
};

const wrapLogger = (logger, thisArg) =>
freeze((...args) => apply(logger, thisArg, args));

Expand Down Expand Up @@ -61,9 +65,9 @@ export const tameConsole = (
unhandledRejectionTrapping = 'report',
optGetStackString = undefined,
) => {
if (consoleTaming !== 'safe' && consoleTaming !== 'unsafe') {
throw TypeError(`unrecognized consoleTaming ${consoleTaming}`);
}
consoleTaming === 'safe' ||
consoleTaming === 'unsafe' ||
failFast(`unrecognized consoleTaming ${consoleTaming}`);

let loggedErrorHandler;
if (optGetStackString === undefined) {
Expand Down Expand Up @@ -105,17 +109,13 @@ export const tameConsole = (
let terminate;
if (errorTrapping === 'platform' || errorTrapping === 'exit') {
const { exit } = globalProcess;
if (typeof exit !== 'function') {
// There is a function-valued process.on but no function-valued process.exit;
// fail early without caring whether errorTrapping is "platform" only by default.
throw TypeError('missing process.exit');
}
// If there is a function-valued process.on but no function-valued process.exit,
// fail early without caring whether errorTrapping is "platform" only by default.
typeof exit === 'function' || failFast('missing process.exit');
terminate = () => exit(globalProcess.exitCode || -1);
} else if (errorTrapping === 'abort') {
terminate = globalProcess.abort;
if (typeof terminate !== 'function') {
throw TypeError('missing process.abort');
}
typeof terminate === 'function' || failFast('missing process.abort');
}

globalProcess.on('uncaughtException', error => {
Expand Down

0 comments on commit 08cbae5

Please sign in to comment.