How to use stack-utils - 10 common examples

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}`)
    }

    console.error(`${chalk.red(`${taskName}.${pluginName}`)}: error`)
github avajs / ava / lib / beautify-stack.js View on Github external
'use strict';
const StackUtils = require('stack-utils');
const cleanStack = require('clean-stack');
const debug = require('debug')('ava');

// Ignore unimportant stack trace lines
let ignoreStackLines = [];

const avaInternals = /\/ava\/(?:lib\/|lib\/worker\/)?[\w-]+\.js:\d+:\d+\)?$/;
const avaDependencies = /\/node_modules\/(?:append-transform|bluebird|empower-core|nyc|require-precompiled|(?:ava\/node_modules\/)?(?:babel-runtime|core-js))\//;
const stackFrameLine = /^.+( \(.+:\d+:\d+\)|:\d+:\d+)$/; // eslint-disable-line prefer-named-capture-group

if (!debug.enabled) {
	ignoreStackLines = StackUtils.nodeInternals();
	ignoreStackLines.push(avaInternals);
	ignoreStackLines.push(avaDependencies);
}

const stackUtils = new StackUtils({internals: ignoreStackLines});

function extractFrames(stack) {
	return stack
		.split('\n')
		.map(line => line.trim())
		.filter(line => stackFrameLine.test(line))
		.join('\n');
}

/*
 * Given a string value of the format generated for the `stack` property of a
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 tapjs / node-tap / lib / stack.js View on Github external
new RegExp(resc(require.resolve('import-jsx'))),
      ]
    : [])
: +process.env.TAP_DEV_LONGSTACK !== 1 ? [
    /at internal\/.*\.js:\d+:\d+/m,
    new RegExp(resc(require.resolve('esm'))),
    new RegExp(resc(require.resolve('nyc').replace(/(node_modules[\/\\]nyc).*$/, '$1'))),
    new RegExp(resc(require.resolve('import-jsx'))),
  ]
: []

sourceMapSupport.install({environment:'node', hookRequire: true})

let nodeInternals = []
try {
  nodeInternals = StackUtils.nodeInternals()
} catch (error) {
  // Do nothing.
}

module.exports = new StackUtils({
  internals: nodeInternals.concat(skip),
  wrapCallSite: sourceMapSupport.wrapCallSite
})
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 avajs / ava / test / fixture / trigger-worker-exception / hack.js View on Github external
'use strict';

const StackUtils = require('stack-utils');

const original = StackUtils.prototype.parseLine;
let restored = false;
let restoreAfterFirstCall = false;
StackUtils.prototype.parseLine = function (line) {
	if (restored) {
		return original.call(this, line);
	}

	if (restoreAfterFirstCall) {
		restored = true;
	}

	throw new Error('Forced error');
};

exports.restoreAfterFirstCall = () => {
	restoreAfterFirstCall = true;
github avajs / ava / test / fixture / trigger-worker-exception / hack.js View on Github external
'use strict';

const StackUtils = require('stack-utils');

const original = StackUtils.prototype.parseLine;
let restored = false;
let restoreAfterFirstCall = false;
StackUtils.prototype.parseLine = function (line) {
	if (restored) {
		return original.call(this, line);
	}

	if (restoreAfterFirstCall) {
		restored = true;
	}

	throw new Error('Forced error');
};

exports.restoreAfterFirstCall = () => {
	restoreAfterFirstCall = true;
};
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,
    }),
  })
}
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,
    }),
  })
}
github keystonejs / keystone / packages / app-graphql / lib / apolloServer.js View on Github external
const { ApolloServer } = require('apollo-server-express');
const { formatError, isInstance: isApolloErrorInstance } = require('apollo-errors');
const ensureError = require('ensure-error');
const serializeError = require('serialize-error');
const StackUtils = require('stack-utils');
const cuid = require('cuid');
const { omit } = require('@keystone-alpha/utils');
const { logger } = require('@keystone-alpha/logger');
const { startAuthedSession, endAuthedSession } = require('@keystone-alpha/session');

const { NestedError } = require('./graphqlErrors');

const graphqlLogger = logger('graphql');

const stackUtil = new StackUtils({ cwd: process.cwd(), internals: StackUtils.nodeInternals() });

const cleanError = maybeError => {
  if (!maybeError.stack) {
    return maybeError;
  }
  maybeError.stack = stackUtil.clean(maybeError.stack);
  return maybeError;
};

const safeFormatError = error => {
  const formattedError = formatError(error, true);
  if (formattedError) {
    return cleanError(formattedError);
  }
  return serializeError(cleanError(error));
};

stack-utils

Captures and cleans stack traces

MIT
Latest version published 2 years ago

Package Health Score

77 / 100
Full package analysis

Similar packages