How to use clean-stack - 6 common examples

To help you get started, we’ve selected a few clean-stack examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tommy351 / kosko / packages / cli / src / cli / error.ts View on Github external
export function formatError(err: Error): string {
  if (!err.stack) return err.message;

  const stack = cleanStack(err.stack, { pretty: true });
  // Regular expression is from: https://github.com/sindresorhus/extract-stack
  const pos = stack.search(/(?:\n {4}at .*)+/);
  if (!~pos) return stack;

  return stack.substring(0, pos) + chalk.gray(stack.substring(pos));
}
github tommy351 / kosko / packages / cli / src / cli / __tests__ / error.ts View on Github external
test("should extract stack properly", () => {
      const [first, second, ...rest] = cleanStack(err.stack!, {
        pretty: true
      }).split("\n");

      expect(stack).toEqual(
        first + "\n" + second + chalk.gray("\n" + rest.join("\n"))
      );
    });
  });
github boltpkg / bolt / src / cli.js View on Github external
logger.title(
    messages.boltVersion(pkg.version),
    messages.nodeVersion(process.versions.node),
    { emoji: '⚡️' }
  );

  processes.handleSignals();

  try {
    await runCommandFromCli(input, flags);
  } catch (err) {
    if (err instanceof BoltError) {
      logger.error(err.message);
    } else {
      logger.error(cleanStack(err.stack));
    }

    if (exit) {
      process.exit(1);
    } else {
      throw err;
    }
  }

  let timing = (Date.now() - start) / 1000;
  let rounded = Math.round(timing * 100) / 100;

  logger.info(messages.doneInSeconds(rounded), {
    emoji: '🏁',
    prefix: false
  });
github dylang / logging / src / formatters / format-color / format-any / format-error.ts View on Github external
export const formatError = (err: Error): string => {
    const { name, message, stack, ...errorMetadata } = serializeError(err);
    const cleanedStack = cleanStack(stack || '').replace(`${name}: ${message}\n`, '');

    const stackWithCodeSnippets = cleanedStack
        .split('\n')
        .map((stackLine: string, index) => getCodeSnippet(stackLine, index === 0 ? message || '' : ''))
        .join('\n');
    const metadataArray = Object.entries(errorMetadata || {});

    const improvedStackArray = [
        chalk.red(`${name}: ${(message || '').replace(cwdRegex, '.')}`),
        '',
        stackWithCodeSnippets,
        metadataArray.length ? ' ' : '',
        metadataArray.map(([key, value]) => chalk`{gray ${key}}: ${formatAny(value)}`).join('\n')
    ];

    return improvedStackArray
github thealjey / webcompiler / src / logger.js View on Github external
export function logError(error: Error) {
  const {name, message, stack} = error;

  log(formatErrorMarker(name), ': ', message);

  error.stack = cleanStack(stack);

  forEach(ErrorStackParser.parse(error), ({functionName = 'unknown', fileName, lineNumber, columnNumber}) => {
    log('  • ', ...formatLine(functionName, fileName, lineNumber, columnNumber));
  });
}
github dylang / logging / src / serializers / serialize-error.ts View on Github external
export const serializeError = (err: Error | unknown) => {
    const errorObject = serializeErrorToObject(err);
    return {
        ...errorObject,
        message: (errorObject.message || '').replace(cwdRegex, '.'),
        stack: cleanStack(errorObject.stack || '').replace(cwdRegex, '.')
    };
};

clean-stack

Clean up error stack traces

MIT
Latest version published 2 years ago

Package Health Score

73 / 100
Full package analysis

Popular clean-stack functions