Skip to content

Instantly share code, notes, and snippets.

@Restuta
Last active March 12, 2020 19:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Restuta/b2ee29ccda90123a93c827b28e92597f to your computer and use it in GitHub Desktop.
Save Restuta/b2ee29ccda90123a93c827b28e92597f to your computer and use it in GitHub Desktop.
neat-stack.js
import cleanStack from 'clean-stack';
// dims non-useful log lines in stack traces
const neatStack = (colorize, stack) => {
// add parts of stack trace lines here that should be ignored
const regexParts = [
'(node_modules)',
'(WEBPACK_IMPORTED)',
'(next_tick.js)',
'(domain.js)',
'(timers.js)',
'(overloadSequlizeFind)',
'(Array.)',
'(at new Promise)',
'(_next)',
'(_callee)',
'(__webpack_require__)',
].join('|');
const internalStackRegex = new RegExp(`at.*${regexParts}`);
const cleanedStack = cleanStack(String(stack));
const stackLines = cleanedStack.split('\n');
const title = R.head(stackLines);
const colorizedStackLines = R.pipe(
R.tail,
R.map(line =>
line.match(internalStackRegex) || line.match('From previous event')
? chalk.dim(line)
: colorize(line),
),
R.join('\n'),
)(stackLines);
return colorize(`${title}\n${colorizedStackLines}`);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment