Code Monkey home page Code Monkey logo

mapstrace's Introduction

Mapstrace

A really simple library for printing human-readable stack-traces for combined, minified and/or compiled javascript files.

It assumes that your javascript file(s) have source maps (index.js -> index.js.map etc).

For example the following stack-trace:

TypeError: Cannot read property 'length' of null
    at $extend.index (/Users/janekp/Documents/wixe/trunk/server/api/web/index.js:103:7)
    at Application.main.wixe1.route.ctx.template (/Users/janekp/Documents/wixe/trunk/server/api/web/index.js:12:24)
    at Object.wixe.Server.handle (/Users/janekp/Documents/wixe/trunk/server/api/web/index.js:253:5)
    at Object.handle (/Users/janekp/Documents/wixe/trunk/server/api/web/index.js:197:8)
    at next (/Users/janekp/Documents/wixe/trunk/server/api/web/node_modules/connect/lib/proto.js:190:15)
    at Function.app.handle (/Users/janekp/Documents/wixe/trunk/server/api/web/node_modules/connect/lib/proto.js:198:3)
    at Server.app (/Users/janekp/Documents/wixe/trunk/server/api/web/node_modules/connect/lib/connect.js:66:31)
    at Server.EventEmitter.emit (events.js:91:17)
    at HTTPParser.parser.onIncoming (http.js:1785:12)
    at HTTPParser.parserOnHeadersComplete [as onHeadersComplete] (http.js:111:23)

becomes developer-friendly:

TypeError: Cannot read property 'length' of null:
    at 'if(x.length == 0) {' (.../trunk/server/api/src/RecipesPage.hx:45:25)
    at 'wixe.get('/:action/:id{0-9}', RecipesPage)' (.../trunk/server/api/src/Application.hx:15:7)
    at 'handler(ctx)' (.../server/api/src/wixe/Server.hx:290:23)
    at 'this.handle(req, res, next)' (.../server/api/src/wixe/Server.hx:306:37)
    ... (omitted 6 rows)

Installation and Dependencies

Install node.js for your platform

npm install mapstrace

It can be used with or without Connect

var mapstrace = require('mapstrace');

// Connect
var connect = require('connect');
connect.createServer().use(connect.static('public')).use(mapstrace()).listen(3000);

// Stand-alone
mapstrace.build(err, true, function(result) {
    console.log(err.toString() + ':\n' + mapstrace.stringify(result));
});

The library can also be used to manually build a list of items and convert them into a string.

// err  - javascript Error object
// full - if true, then it will parse source files to fill missing fields.
// fn   - asynchronous callback that returns a list of items.
//        The list can contain objects and integers. Integers are used for unknown external items.
//        Every item has lineNumber, columnNumber, source and name fields.
mapstrace.build(err : Error, full : Bool, fn : Array -> Void) : Void;

// items  - A list of stack items (either numbers or objects).
// prefix - If not null then prefix is removed from paths. Optional, default is null
// limit  - The max number of path components. Optional, default is 5
// Returns a string.
mapstrace.stringify(items : Array, prefix : String, limit : Int) : String;

mapstrace's People

Contributors

janekp avatar

Watchers

James Cloos avatar Zack Feldstein avatar Bruno Gobbi avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.