Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

stackman

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stackman

Enhance an error stacktrace with code excerpts and other goodies

  • 0.1.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
13K
increased by24.07%
Maintainers
1
Weekly downloads
 
Created
Source

Stackman

Give Stackman an error and he will give an array of stack frames with extremely detailed information for each frame in the stack trace.

With Stackman you get access to the actual source code and surrounding lines for where the error occured, you get to know if it happended inside a 3rd party module, in Node.js or in your own code. For a full list of information, check out the API below.

build status

Install

npm install stackman

Basic usage

var stackman = require('stackman')();

var err = new Error('Oops!');

stackman(err, function (stack) {
  // stack is an array of callsite objects
  stack.forEach(function (frame) {
    // output: <example.js:3> var err = new Error('Oops!');
    console.log('<%s:%s> %s',
      frame.getFileName(),
      frame.getLineNumber(),
      frame.context.line);
  });
});

API

Module

Parse options to the main stackman function to customize the default behavior:

var options = { context: 5 };
var stackman = require('stackman')(options);

The stackman function takes two arguments:

  • err - the error to be parsed
  • callback - a callback which will be called with an array of callsite stack-frames when the parsing is completed

Callsite

Custom properties
  • callsite.context.pre - The lines before the main callsite line
  • callsite.context.line - The main callsite line
  • callsite.context.post - The lines after the main callsite line
Custom methods
  • callsite.getFunctionNameSanitized() - Guaranteed to always return the most meaningful function name. If none can be determined, the string <anonymous> will be returned
  • callsite.getModuleName() - Returns the name of the module if isModule() is true
  • callsite.isApp() - Is this inside the app? (i.e. not native, not node code and not a nodule inside the node_modules directory)
  • callsite.isModule() - Is this inside the node_modules directory?
  • callsite.isNode() - Is this inside node core?
Methods inherited from V8

The follwoing methods are inherited from the V8 stack trace API.

  • callsite.getThis() - returns the value of this
  • callsite.getTypeName() - returns the type of this as a string. This is the name of the function stored in the constructor field of this, if available, otherwise the object's [[Class]] internal property.
  • callsite.getFunction() - returns the current function
  • callsite.getFunctionName() - returns the name of the current function, typically its name property. If a name property is not available an attempt will be made to try to infer a name from the function's context.
  • callsite.getMethodName() - returns the name of the property of this or one of its prototypes that holds the current function
  • callsite.getFileName() - if this function was defined in a script returns the name of the script
  • callsite.getLineNumber() - if this function was defined in a script returns the current line number
  • callsite.getColumnNumber() - if this function was defined in a script returns the current column number
  • callsite.getEvalOrigin() - if this function was created using a call to eval returns a CallSite object representing the location where eval was called
  • callsite.isToplevel() - is this a toplevel invocation, that is, is this the global object?
  • callsite.isEval() - does this call take place in code defined by a call to eval?
  • callsite.isNative() - is this call in native V8 code?
  • callsite.isConstructor() - is this a constructor call?

License

MIT

Keywords

FAQs

Package last updated on 30 Jul 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc