Skip to content

Non zero exit code for errors #175

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bin/commands/generateDownloads.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@ module.exports = async function generateDownloads(args) {
logger.error(err);
utils.setUsageReportingFlag(null, args.disableUsageReporting);
utils.sendUsageReport(null, args, err.message, Constants.messageTypes.ERROR, utils.getErrorCodeFromErr(err));
process.exitCode = Constants.ERROR_EXIT_CODE;
});
};
1 change: 1 addition & 0 deletions bin/commands/generateReport.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ module.exports = function generateReport(args) {
logger.error(err);
utils.setUsageReportingFlag(null, args.disableUsageReporting);
utils.sendUsageReport(null, args, err.message, Constants.messageTypes.ERROR, utils.getErrorCodeFromErr(err));
process.exitCode = Constants.ERROR_EXIT_CODE;
});
};
1 change: 1 addition & 0 deletions bin/commands/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,6 @@ module.exports = function info(args) {
logger.error(err);
utils.setUsageReportingFlag(null, args.disableUsageReporting);
utils.sendUsageReport(null, args, err.message, Constants.messageTypes.ERROR, utils.getErrorCodeFromErr(err));
process.exitCode = Constants.ERROR_EXIT_CODE;
})
}
6 changes: 6 additions & 0 deletions bin/commands/runs.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ module.exports = function run(args) {
await utils.stopLocalBinary(bsConfig, bs_local, args);

utils.sendUsageReport(bsConfig, args, err, Constants.messageTypes.ERROR, 'build_failed');
process.exitCode = Constants.ERROR_EXIT_CODE;
});
}).catch(function (err) {
// Zip Upload failed | Local Start failed
Expand All @@ -200,6 +201,7 @@ module.exports = function run(args) {
fileHelpers.deleteZip();
utils.sendUsageReport(bsConfig, args, `${err}\n${Constants.userMessages.ZIP_UPLOAD_FAILED}`, Constants.messageTypes.ERROR, 'zip_upload_failed');
}
process.exitCode = Constants.ERROR_EXIT_CODE;
});
}).catch(function (err) {
// Zipping failed
Expand All @@ -211,12 +213,14 @@ module.exports = function run(args) {
} catch (err) {
utils.sendUsageReport(bsConfig, args, Constants.userMessages.ZIP_DELETE_FAILED, Constants.messageTypes.ERROR, 'zip_deletion_failed');
}
process.exitCode = Constants.ERROR_EXIT_CODE;
});
}).catch(function (err) {
// md5 check failed
logger.error(err);
logger.error(Constants.userMessages.FAILED_MD5_CHECK);
utils.sendUsageReport(bsConfig, args, Constants.userMessages.MD5_CHECK_FAILED, Constants.messageTypes.ERROR, 'zip_already_uploaded_failed');
process.exitCode = Constants.ERROR_EXIT_CODE;
});
}).catch(function (err) {
// browerstack.json is not valid
Expand All @@ -230,10 +234,12 @@ module.exports = function run(args) {

let error_code = utils.getErrorCodeFromMsg(err);
utils.sendUsageReport(bsConfig, args, `${err}\n${Constants.validationMessages.NOT_VALID}`, Constants.messageTypes.ERROR, error_code);
process.exitCode = Constants.ERROR_EXIT_CODE;
});
}).catch(function (err) {
logger.error(err);
utils.setUsageReportingFlag(null, args.disableUsageReporting);
utils.sendUsageReport(null, args, err.message, Constants.messageTypes.ERROR, utils.getErrorCodeFromErr(err));
process.exitCode = Constants.ERROR_EXIT_CODE;
});
}
1 change: 1 addition & 0 deletions bin/commands/stop.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,6 @@ module.exports = function stop(args) {
logger.error(err);
utils.setUsageReportingFlag(null, args.disableUsageReporting);
utils.sendUsageReport(null, args, err.message, Constants.messageTypes.ERROR, utils.getErrorCodeFromErr(err));
process.exitCode = Constants.ERROR_EXIT_CODE;
})
}
2 changes: 2 additions & 0 deletions bin/helpers/buildArtifacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ exports.downloadBuildArtifacts = async (bsConfig, buildId, args) => {
messageType = Constants.messageTypes.ERROR;
message = Constants.userMessages.DOWNLOAD_BUILD_ARTIFACTS_FAILED.replace('<build-id>', buildId).replace('<machine-count>', BUILD_ARTIFACTS_FAIL_COUNT);
logger.error(message);
process.exitCode = Constants.ERROR_EXIT_CODE;
} else {
messageType = Constants.messageTypes.SUCCESS;
message = Constants.userMessages.DOWNLOAD_BUILD_ARTIFACTS_SUCCESS.replace('<build-id>', buildId).replace('<user-path>', process.cwd());
Expand All @@ -214,5 +215,6 @@ exports.downloadBuildArtifacts = async (bsConfig, buildId, args) => {
}

utils.sendUsageReport(bsConfig, args, err, messageType, errorCode);
process.exitCode = Constants.ERROR_EXIT_CODE;
}
};
5 changes: 4 additions & 1 deletion bin/helpers/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ const usageReportingConstants = {

const LATEST_VERSION_SYNTAX_REGEX = /\d*.latest(.\d*)?/gm

const ERROR_EXIT_CODE = 1;

module.exports = Object.freeze({
syncCLI,
userMessages,
Expand All @@ -203,5 +205,6 @@ module.exports = Object.freeze({
SPEC_TOTAL_CHAR_LIMIT,
METADATA_CHAR_BUFFER_PER_SPEC,
usageReportingConstants,
LATEST_VERSION_SYNTAX_REGEX
LATEST_VERSION_SYNTAX_REGEX,
ERROR_EXIT_CODE
});
10 changes: 8 additions & 2 deletions bin/helpers/reporterHTML.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,10 @@ function generateCypressCombinationSpecReportDataWithConfigJson(combination){
});
combination.tests = sessionTests;
resolve(combination.tests);
} catch (error) { reject(error) }
} catch (error) {
process.exitCode = Constants.ERROR_EXIT_CODE;
reject(error);
}
})
}

Expand Down Expand Up @@ -308,7 +311,10 @@ function generateCypressCombinationSpecReportDataWithoutConfigJson(combination){
});
combination.tests = sessionTests;
resolve(combination.tests);
} catch (error) { reject(error) }
} catch (error) {
process.exitCode = Constants.ERROR_EXIT_CODE;
reject(error);
}
})
}

Expand Down