All Projects β†’ xpl β†’ Stacktracey

xpl / Stacktracey

Licence: unlicense
Parses call stacks. Reads sources. Clean & filtered output. Sourcemaps. Node & browsers.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Stacktracey

Traceback with variables
Adds variables to python traceback. Simple, lightweight, controllable. Debug reasons of exceptions by logging or pretty printing colorful variable contexts for each frame in a stacktrace, showing every value. Dump locals environments after errors to console, files, and loggers. Works in Jupyter and IPython. Install with pip or conda.
Stars: ✭ 509 (+342.61%)
Mutual labels:  error-handling, logging, exception-handling
Tslog
πŸ“ tslog - Expressive TypeScript Logger for Node.js.
Stars: ✭ 321 (+179.13%)
Mutual labels:  stack, error-handling, logging
Log Process Errors
Show some ❀️ to Node.js process errors
Stars: ✭ 424 (+268.7%)
Mutual labels:  error-handling, logging
Bugsnag Php
Bugsnag error monitoring and crash reporting tool for PHP apps
Stars: ✭ 475 (+313.04%)
Mutual labels:  error-handling, exception-handling
Bugsnag Js
Javascript error handling tool for Bugsnag. Monitor and report JavaScript bugs & errors.
Stars: ✭ 625 (+443.48%)
Mutual labels:  error-handling, exception-handling
Aspnetcore Webapi Course
Professional REST API design with ASP.NET Core 3.1 WebAPI
Stars: ✭ 323 (+180.87%)
Mutual labels:  logging, exception-handling
Bugsnag React Native
Error monitoring and reporting tool for native exceptions and JS errors in React Native apps
Stars: ✭ 374 (+225.22%)
Mutual labels:  error-handling, exception-handling
Bash Oo Framework
Bash Infinity is a modern standard library / framework / boilerplate for Bash
Stars: ✭ 5,247 (+4462.61%)
Mutual labels:  error-handling, logging
catchr
catchr: Flexible, useful tools for dealing with conditions in R, for new users and veterans
Stars: ✭ 17 (-85.22%)
Mutual labels:  error-handling, exception-handling
Mjn
⚑️Like loadash.get, but in ~200 bytes
Stars: ✭ 69 (-40%)
Mutual labels:  error-handling, exception-handling
Panic Overlay
Displays JS errors in browsers. Shows sources. Use with any framework. πŸ’₯✨
Stars: ✭ 50 (-56.52%)
Mutual labels:  stack, error-handling
React Native Device Log
A UI and service for handling/displaying dev log messages on devices
Stars: ✭ 96 (-16.52%)
Mutual labels:  error-handling, logging
react-error-guard
βš›οΈAn overlay for displaying stack frames based on create-react-app/packages/react-error-overlay
Stars: ✭ 18 (-84.35%)
Mutual labels:  error-handling, exception-handling
ignition-stackoverflow
An Ignition tab that fetches StackOverflow questions and provides a searchbar.
Stars: ✭ 74 (-35.65%)
Mutual labels:  error-handling, exception-handling
bugsnag-java
Bugsnag error reporting for Java.
Stars: ✭ 51 (-55.65%)
Mutual labels:  error-handling, exception-handling
Production Ready Expressjs Server
Express.js server that implements production-ready error handling and logging following latest best practices.
Stars: ✭ 101 (-12.17%)
Mutual labels:  error-handling, logging
Exceptions4c
πŸ‘ An exception handling framework for C
Stars: ✭ 189 (+64.35%)
Mutual labels:  error-handling, exception-handling
cakephp-error-email
ErrorEmail Plugin for CakePHP3.x
Stars: ✭ 16 (-86.09%)
Mutual labels:  error-handling, exception-handling
Thoth
An Error Logger for Go
Stars: ✭ 22 (-80.87%)
Mutual labels:  error-handling, logging
Faux Pas
A library that simplifies error handling for Functional Programming in Java
Stars: ✭ 100 (-13.04%)
Mutual labels:  error-handling, exception-handling

StackTracey

Build Status Windows Build Status Coverage Status NPM Scrutinizer Code Quality dependencies Status

Parses call stacks. Reads sources. Clean & filtered output. Sourcemaps. Node & browsers.

Why

  • [x] Simple
  • [x] Works in Node and browsers, *nix and Windows
  • [x] Allows hiding library calls / ad-hoc exclusion (via // @hide marker)
  • [x] Provides source text for call locations
  • [x] Fetches sources (via get-source)
  • [x] Supports both asynchronous and synchronous interfaces (works even in browsers)
  • [x] Full sourcemap support
  • [x] Extracts useful information from SyntaxError instances
  • [x] Pretty printing screen shot 2017-09-27 at 16 53 46

What For

How To

npm install stacktracey
import StackTracey from 'stacktracey'

Captures the current call stack:

stack = new StackTracey ()            // captures the current call stack

Parses stacks from an Error object:

stack = new StackTracey (error)
stack = new StackTracey (error.stack) // ...or from raw string

Stores parsed data in .items:

stack.items.length // num entries
stack.items[0]     // top

...where each item exposes:

{
    beforeParse:  <original text>,
    callee:       <function name>,
    calleeShort:  <shortened function name>,
    file:         <full path to file>,       // e.g. /Users/john/my_project/node_modules/foobar/main.js
    fileRelative: <relative path to file>,   // e.g. node_modules/foobar/main.js
    fileShort:    <short path to file>,      // e.g. foobar/main.js
    fileName:     <file name>,               // e.g. main.js
    line:         <line number>,             // starts from 1
    column:       <column number>,           // starts from 1

    index:          /* true if occured in HTML file at index page    */,
    native:         /* true if occured in native browser code        */,
    thirdParty:     /* true if occured in library code               */,
    hide:           /* true if marked as hidden by "// @hide" tag    */,
    syntaxError:    /* true if generated from a SyntaxError instance */
}

Accessing sources (synchronously, use with caution in browsers):

stack = stack.withSources () // returns a copy of stack with all items supplied with sources
top   = stack.items[0]       // top item

Accessing sources (asynchronously, preferred method in browsers):

stack = await stack.withSourcesAsync () // returns a copy of stack with all items supplied with sources
top   = stack.items[0]                  // top item

...or:

top = stack.withSourceAt (0) // supplies source for an individiual item (by index)
top = await stack.withSourceAsyncAt (0) // supplies source for an individiual item (by index)

...or:

top = stack.withSource (stack.items[0]) // supplies source for an individiual item
top = await stack.withSourceAsync (stack.items[0]) // supplies source for an individiual item

The returned items contain the following additional fields (already mapped through sourcemaps):

{
    ... // all the previously described fields

    line:       <original line number>,
    column:     <original column number>,
    sourceFile: <original source file object>,
    sourceLine: <original source line text>
}

To learn about the sourceFile object, read the get-source docs.

Cleaning Output

Synchronously (use with caution in browsers):

stack = stack.clean ()

...or (asynchronously):

stack = await stack.cleanAsync ()

It does the following:

  1. Reads sources (if available)
  2. Excludes locations marked with the isThirdParty flag (library calls)
  3. Excludes locations marked with a // @hide comment (user defined exclusion)
  4. Merges repeated lines (via the .mergeRepeatedLines)

You can customize its behavior by overriding the isClean (entry, index) predicate.

Custom isThirdParty Predicate

You can override the isThirdParty behavior by subclassing StackTracey:

class MyStackTracey extends StackTracey {

    isThirdParty (path) {
        return (super.isThirdParty (path)    // include default behavior
                || path.includes ('my-lib')) // paths including 'my-lib' will be marked as thirdParty
                && !path.includes ('jquery') // jquery paths won't be marked as thirdParty
    }
}

...

const stack = new MyStackTracey (error).withSources ()

Pretty Printing

const prettyPrintedString = new StackTracey (error).withSources ().asTable ()
const prettyPrintedString = (await new StackTracey (error).withSourcesAsync ()).asTable () // asynchronous version

...or (for pretty printing cleaned output):

const prettyPrintedString = new StackTracey (error).clean ().asTable ()
const prettyPrintedString = (await new StackTracey (error).cleanAsync ()).asTable () // asynchronous version

It produces a nice compact table layout (thanks to as-table), supplied with source lines (if available):

at shouldBeVisibleInStackTrace     test.js:25                 const shouldBeVisibleInStackTrace = () => new StackTracey ()
at it                              test.js:100                const stack = shouldBeVisibleInStackTrace ()                
at callFn                          mocha/lib/runnable.js:326  var result = fn.call(ctx);                                  
at run                             mocha/lib/runnable.js:319  callFn(this.fn);                                            
at runTest                         mocha/lib/runner.js:422    test.run(fn);                                               
at                                 mocha/lib/runner.js:528    self.runTest(function(err) {                                
at next                            mocha/lib/runner.js:342    return fn();                                                
at                                 mocha/lib/runner.js:352    next(suites.pop());                                         
at next                            mocha/lib/runner.js:284    return fn();                                                
at <anonymous>                     mocha/lib/runner.js:320    next(0);                  

If you find your pretty printed tables undesirably trimmed (or maybe too long to fit in the line), you can provide custom column widths when calling asTable (...or, alternatively, by overriding maxColumnWidths () method):

stack.asTable ({
    callee:     30,
    file:       60,
    sourceLine: 80
})

Using As A Custom Exception Printer In Node

You can even replace the default NodeJS exception printer with this! This is how you can do it:

process.on ('uncaughtException',  e => { /* print the stack here */ })
process.on ('unhandledRejection', e => { /* print the stack here */ })

But the most simple way to achieve that is to use the ololog library (that is built upon StackTracey and several other handy libraries coded by me). Check it out, it's pretty awesome and will blow your brains out :)

const log = require ('ololog').handleNodeErrors ()

// you can also print Errors by simply passing them to the log() function
screen shot 2018-05-11 at 19 51 03

Parsing SyntaxError instances

For example, when trying to require a file named test_files/syntax_error.js:

// next line contains a syntax error (not a valid JavaScript)
foo->bar ()

...the pretty printed call stack for the error thrown would be something like:

at (syntax error)                  test_files/syntax_error.js:2  foo->bar ()
at it                              test.js:184                   try { require ('./test_files/syntax_error.js') }
at runCallback                     timers.js:781
at tryOnImmediate                  timers.js:743
at processImmediate [as _immediat  timers.js:714

...where the first line is generated from parsing the raw output from the util.inspect call in Node. Unfortunately, this won't work in older versions of Node (v4 and below) as these versions can't provide any meaningful information for a SyntaxError instance.

Array Methods

All StackTracey instances expose map, filter, concat and slice methods. These methods will return mapped, filtered, joined, reversed and sliced StackTracey instances, respectively:

s = new StackTracey ().slice (1).filter (x => !x.thirdParty) // current stack shifted by 1 and cleaned from library calls

s instanceof StackTracey // true

Extra Stuff

You can compare two locations via this predicate (tests file, line and column for equality):

StackTracey.locationsEqual (a, b)

To force-reload the sources, you can invalidate the global source cache:

StackTracey.resetCache ()

Projects That Use StackTracey

  • Ololog β€” a better console.log for the log-driven debugging junkies!
  • CCXT β€” a cryptocurrency trading library that supports 130+ exchanges
  • pnpm β€” a fast, disk space efficient package manager (faster than npm and Yarn!)
  • panic-overlay β€” a lightweight standalone alternative to react-error-overlay
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].