How to use the stack-utils function in stack-utils

To help you get started, we’ve selected a few stack-utils 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 deepsweet / start / packages / reporter-verbose / src / index.ts View on Github external
emitter.on('error', (pluginName: string, error: StartError) => {
    // hard error
    if (error instanceof Error) {
      const stackUtils = new StackUtils({
        cwd: process.cwd(),
        internals: StackUtils.nodeInternals()
      })
      const stack = stackUtils.clean(error.stack!)

      console.error(`${chalk.red(`${taskName}.${pluginName}`)}: ${error.message}`)
      console.error(`\n${chalk.red(stack)}`)
    // array of "soft" errors
    } else if (Array.isArray(error)) {
      error.forEach((message) => {
        console.error(`${chalk.red(`${taskName}.${pluginName}`)}: ${message}`)
      })
    // "soft" error
    } else if (typeof error === 'string') {
      console.error(`${chalk.red(`${taskName}.${pluginName}`)}: ${error}`)
    }
github coralproject / talk / src / core / server / logger / serializers.ts View on Github external
import { GraphQLError } from "graphql";
import StackUtils from "stack-utils";

import { CoralError, CoralErrorContext } from "coral-server/errors";
import VError from "verror";

interface SerializedError {
  id?: string;
  message: string;
  name: string;
  stack?: string;
  context?: CoralErrorContext | Record;
  originalError?: SerializedError;
}

const stackUtils = new StackUtils();

const errSerializer = (err: Error) => {
  const obj: SerializedError = {
    message: err.message,
    name: err.name,
  };

  if (err.stack) {
    // Copy over a cleaned stack.
    obj.stack = stackUtils.clean(err.stack);
  }

  if (err instanceof GraphQLError && err.originalError) {
    // If the error was caused by another error, integrate it.
    obj.originalError = errSerializer(err.originalError);
  } else if (err instanceof CoralError) {
github cucumber / cucumber / fake-cucumber / javascript / src / SupportCode.ts View on Github external
function getSourceReference(stackTrace: string): messages.ISourceReference {
  const stack = new StackUtils({
    cwd: process.cwd(),
    internals: StackUtils.nodeInternals(),
  })
  const trace = stack.clean(stackTrace)
  const callSite = stack.parseLine(trace.split('\n')[1])
  const { file: uri, line } = callSite
  return new messages.SourceReference({
    uri,
    location: new messages.Location({
      line,
    }),
  })
}

stack-utils

Captures and cleans stack traces

MIT
Latest version published 2 years ago

Package Health Score

77 / 100
Full package analysis