Skip to content

Commit

Permalink
feat: should print error stack (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
atian25 authored Apr 23, 2019
1 parent 619c1bf commit 5c621f6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions test/fixtures/my-egg-bin/lib/cmd/error.js
Original file line number Diff line number Diff line change
@@ -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;
9 changes: 9 additions & 0 deletions test/my-egg-bin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.