Skip to content
Permalink
Browse files

feat: should print error stack (#132)

  • Loading branch information
atian25 committed Apr 23, 2019
1 parent 619c1bf commit 5c621f6d6119fc0ac03b70e294e6cc18d2f88568
Showing with 30 additions and 0 deletions.
  1. +9 −0 lib/command.js
  2. +12 −0 test/fixtures/my-egg-bin/lib/cmd/error.js
  3. +9 −0 test/my-egg-bin.test.js
@@ -31,6 +31,15 @@ class Command extends BaseCommand {
};
}

/**
* default error handler
* @param {Error} err - err obj
*/
errorHandler(err) {
console.error(err);
process.nextTick(() => process.exit(1));
}

get context() {
const context = super.context;
const { argv, debugPort, execArgvObj, cwd, env } = context;
@@ -0,0 +1,12 @@
'use strict';

const Command = require('../../../../../');

class ErrorCommand extends Command {
* run() {
const err = new Error('this is an error');
throw err;
}
}

module.exports = ErrorCommand;
@@ -89,4 +89,13 @@ describe('test/my-egg-bin.test.js', () => {
.expect('code', 0)
.end(done);
});

it('should log err stack', done => {
coffee.fork(eggBin, [ 'error' ], { cwd })
.debug()
.expect('stderr', /Error: this is an error/)
.expect('stderr', /fixtures\/my-egg-bin\/lib\/cmd\/error.js:/)
.expect('code', 1)
.end(done);
});
});

0 comments on commit 5c621f6

Please sign in to comment.
You can’t perform that action at this time.