Skip to content

Commit a79c470

Browse files
Xenonymyamgent
authored andcommitted
Exit MarkBind with nonzero exit code on error (MarkBind#679)
1 parent 83ae743 commit a79c470

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

index.js

+11-15
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ function printHeader() {
3131
logger.log(` v${CLI_VERSION}`);
3232
}
3333

34+
function handleError(error) {
35+
logger.error(error.message);
36+
process.exitCode = 1;
37+
}
38+
3439
program
3540
.allowUnknownOption()
3641
.usage(' <command>');
@@ -49,9 +54,7 @@ program
4954
.then(() => {
5055
logger.info('Initialization success.');
5156
})
52-
.catch((error) => {
53-
logger.error(error.message);
54-
});
57+
.catch(handleError);
5558
});
5659

5760
program
@@ -68,7 +71,7 @@ program
6871
try {
6972
rootFolder = cliUtil.findRootFolder(userSpecifiedRoot);
7073
} catch (err) {
71-
logger.error(err.message);
74+
handleError(err);
7275
}
7376
const logsFolder = path.join(rootFolder, '_markbind/logs');
7477
const outputFolder = path.join(rootFolder, '_site');
@@ -159,9 +162,7 @@ program
159162
logger.info('Press CTRL+C to stop ...');
160163
});
161164
})
162-
.catch((error) => {
163-
logger.error(error.message);
164-
});
165+
.catch(handleError);
165166
});
166167

167168
program
@@ -176,10 +177,7 @@ program
176177
.then(() => {
177178
logger.info('Deployed!');
178179
})
179-
.catch((err) => {
180-
logger.error(err.message);
181-
process.exitCode = 1;
182-
});
180+
.catch(handleError);
183181
printHeader();
184182
});
185183

@@ -196,7 +194,7 @@ program
196194
try {
197195
rootFolder = cliUtil.findRootFolder(userSpecifiedRoot);
198196
} catch (err) {
199-
logger.error(err.message);
197+
handleError(err);
200198
}
201199
const defaultOutputRoot = path.join(rootFolder, '_site');
202200
const outputFolder = output ? path.resolve(process.cwd(), output) : defaultOutputRoot;
@@ -206,9 +204,7 @@ program
206204
.then(() => {
207205
logger.info('Build success!');
208206
})
209-
.catch((error) => {
210-
logger.error(error.message);
211-
});
207+
.catch(handleError);
212208
});
213209

214210
program.parse(process.argv);

0 commit comments

Comments
 (0)