Simplify exit code logic. (#4063)

* Simplify exit code logic.

I introduced a bug when I added support for exit codes from
Browsertime/scripting. This fixed that bug and makes the code
simpler to read/understand.

https://github.com/sitespeedio/sitespeed.io/issues/4062
This commit is contained in:
Peter Hedenskog 2024-01-17 14:40:46 +01:00 committed by GitHub
parent f3a28fa731
commit c202151738
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 12 additions and 7 deletions

View File

@ -117,7 +117,6 @@ async function api(options) {
async function start() {
let parsed = await parseCommandLine();
let budgetFailing = false;
// hack for getting in the unchanged cli options
parsed.options.explicitOptions = parsed.explicitOptions;
parsed.options.urls = parsed.urls;
@ -156,21 +155,27 @@ async function start() {
}
}
// If we have a failing budget, change the exit code
if (
parsed.options.budget &&
Object.keys(result.budgetResult.failing).length > 0
) {
process.exitCode = 1;
budgetFailing = true;
}
if (
(!budgetFailing ||
(parsed.options.budget && parsed.options.budget.suppressExitCode)) &&
process.exitCode === undefined
// If you supress the exit code using budgets, we will always return 0
else if (
parsed.options.budget &&
parsed.options.budget.suppressExitCode
) {
process.exitCode = 0;
}
// If the exit code is still not set (it can be set in the scripting also)
// Make sure we exit with a 0
if (process.exitCode === undefined) {
process.exitCode = 0;
}
if (result.errors.length > 0) {
console.log('Errors while running:\n' + result.errors.join('\n'));
throw new Error('Errors while running:\n' + result.errors.join('\n'));