Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 450f85a

Browse files
exit with error code if necessary
Signed-off-by: Eric Wang <skygragon@gmail.com>
1 parent fc4f4ac commit 450f85a

File tree

7 files changed

+20
-11
lines changed

7 files changed

+20
-11
lines changed

‎lib/cli.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ cli.run = function() {
9898
initLogLevel();
9999
initDir()
100100
initPlugins(function(e) {
101-
if (e) return log.error(e);
101+
if (e) return log.fatal(e);
102102
cache.init();
103103
runCommand();
104104
});

‎lib/commands/config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,14 @@ cmd.handler = function(argv) {
7575

7676
// delete
7777
if (argv.delete) {
78-
if (v === undefined) return log.error('Key not found: ' + argv.key);
78+
if (v === undefined) return log.fatal('Key not found: ' + argv.key);
7979
nconf.clear(argv.key);
8080
return saveConfig();
8181
}
8282

8383
// show
8484
if (argv.value.length === 0) {
85-
if (v === undefined) return log.error('Key not found: ' + argv.key);
85+
if (v === undefined) return log.fatal('Key not found: ' + argv.key);
8686
return log.info(prettyConfig(v));
8787
}
8888

‎lib/commands/plugin.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ cmd.handler = function(argv) {
8080

8181
if (argv.install) {
8282
const cb = function(e, p) {
83-
if (e) return log.error(e);
83+
if (e) return log.fatal(e);
8484
p.help();
8585
p.save();
8686
Plugin.init();
@@ -96,11 +96,11 @@ cmd.handler = function(argv) {
9696
}
9797

9898
if (name) plugins = plugins.filter(x => x.name === name);
99-
if (plugins.length === 0) return log.error('Plugin not found!');
99+
if (plugins.length === 0) return log.fatal('Plugin not found!');
100100

101101
const p = plugins[0];
102102
if (p.missing && (argv.enable || argv.disable))
103-
return log.error('Plugin missing, install it first');
103+
return log.fatal('Plugin missing, install it first');
104104

105105
if (argv.enable) {
106106
p.enabled = true;

‎lib/commands/submit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function printLine() {
4444
cmd.handler = function(argv) {
4545
session.argv = argv;
4646
if (!file.exist(argv.filename))
47-
return log.error('File ' + argv.filename + ' not exist!');
47+
return log.fatal('File ' + argv.filename + ' not exist!');
4848

4949
const meta = file.meta(argv.filename);
5050

‎lib/commands/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ function printResult(actual, expect, k) {
5454

5555
function runTest(argv) {
5656
if (!file.exist(argv.filename))
57-
return log.error('File ' + argv.filename + ' not exist!');
57+
return log.fatal('File ' + argv.filename + ' not exist!');
5858

5959
const meta = file.meta(argv.filename);
6060

‎lib/log.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,16 @@ log.isEnabled = function(name) {
2525
};
2626

2727
log.fail = function(e) {
28-
log.error(sprintf('%s [%d]', (e.msg || e), (e.statusCode || 0)));
28+
let msg = sprintf('%s', (e.msg || e));
29+
if (e.statusCode) {
30+
msg += sprintf(' [code=%d]', e.statusCode);
31+
}
32+
log.error(msg);
33+
};
34+
35+
log.fatal = function(e) {
36+
log.error(e);
37+
process.exit(1);
2938
};
3039

3140
log.printf = function() {

‎test/test_log.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ describe('log', function() {
9393

9494
it('should ok with log.fail', function() {
9595
log.fail({msg: 'some error', statusCode: 500});
96-
assert.equal(expected, chalk.red('[ERROR] some error [500]'));
96+
assert.equal(expected, chalk.red('[ERROR] some error [code=500]'));
9797

9898
log.fail('some error');
99-
assert.equal(expected, chalk.red('[ERROR] some error [0]'));
99+
assert.equal(expected, chalk.red('[ERROR] some error'));
100100
});
101101
}); // #levels
102102

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /