bjyoungblood / es6-error

Easily-extendable error for use with ES6 classes

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Does not work in combination with longjohn

gajus opened this issue · comments

When used in combination with https://github.com/mattinsler/longjohn, produces no stack trace.

Extending Error object directly:

/Users/gajus/Documents/dev/gajus/mightyql/dist/index.js:86
    throw new _errors.NotFoundError();
          ^
Error: Resource not found.
    at exports.many (/Users/gajus/Documents/dev/gajus/mightyql/dist/index.js:86:11)
---------------------------------------------
    at Object.<anonymous> (/Users/gajus/Documents/dev/applaudience/showtime-api/src/bin/server.js:42:9)
    at Module._compile (module.js:571:32)
    at loader (/Users/gajus/Documents/dev/applaudience/showtime-api/node_modules/babel-register/lib/node.js:144:5)
    at Object.require.extensions.(anonymous function) [as .js] (/Users/gajus/Documents/dev/applaudience/showtime-api/node_modules/babel-register/lib/node.js:154:7)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Function.Module.runMain (module.js:605:10)
    at Object.<anonymous> (/Users/gajus/Documents/dev/applaudience/showtime-api/node_modules/babel-cli/lib/_babel-node.js:154:22)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.runMain (module.js:605:10)

Extending es6-error:

/Users/gajus/Documents/dev/gajus/mightyql/dist/index.js:86
    throw new _errors.NotFoundError();
          ^
NotFoundError: Resource not found.
    at exports.many (/Users/gajus/Documents/dev/gajus/mightyql/dist/index.js:86:11)

This is a major bummer, because it makes it impossible to debug code that uses setTimeout, setImmediate, nextTick.

Can you provide a simple example that causes this? Using node v7.7.4, the following script gave correct-looking output (I also tried simpler cases with just setTimeout, nextTick):

require('longjohn');
const { EventEmitter } = require('events');
const ExtendableError = require('es6-error');

class NotFoundError extends ExtendableError {}

class MyEE extends EventEmitter {
  emitErr() {
    this.emit('error', new NotFoundError('not found'));
  }
}

let x = new MyEE();

function causeAnErrorSoon() {
  setTimeout(function() {
    x.emitErr();
  }, 500);
}

causeAnErrorSoon();

Output:

/Users/bjy/workspace/es6-error/test.js:9
    this.emit('error', new NotFoundError('not found'));
                       ^
NotFoundError: not found
    at MyEE.emitErr (/Users/bjy/workspace/es6-error/test.js:9:24)
    at Timeout.<anonymous> (/Users/bjy/workspace/es6-error/test.js:17:7)
    at ontimeout (timers.js:380:14)
    at tryOnTimeout (timers.js:244:5)
    at Timer.listOnTimeout (timers.js:214:5)
---------------------------------------------
    at causeAnErrorSoon (/Users/bjy/workspace/es6-error/test.js:16:3)
    at Object.<anonymous> (/Users/bjy/workspace/es6-error/test.js:21:1)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.runMain (module.js:605:10)
    at run (bootstrap_node.js:427:7)

I think I rushed to report this issue. There is something low level going on that I haven't managed to isolate yet. Sorry.

Closing this for now.

I think I rushed to report this issue. There is something low level going on that I haven't managed to isolate yet. Sorry.

I am not even able to get the expected stack traces with:

console.log( "new Error('test').stack", new Error('test').stack );

just before throwing the error.

No worries! Feel free to reopen if it ends up being an issue with es6-error.