Skip to content

Commit 4a7acc7

Browse files
Merge pull request #175 from browserstack/exit_code
Non zero exit code for errors
2 parents a81ed43 + 833ed8e commit 4a7acc7

File tree

8 files changed

+24
-3
lines changed

8 files changed

+24
-3
lines changed

bin/commands/generateDownloads.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,6 @@ module.exports = async function generateDownloads(args) {
3434
logger.error(err);
3535
utils.setUsageReportingFlag(null, args.disableUsageReporting);
3636
utils.sendUsageReport(null, args, err.message, Constants.messageTypes.ERROR, utils.getErrorCodeFromErr(err));
37+
process.exitCode = Constants.ERROR_EXIT_CODE;
3738
});
3839
};

bin/commands/generateReport.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,6 @@ module.exports = function generateReport(args) {
3535
logger.error(err);
3636
utils.setUsageReportingFlag(null, args.disableUsageReporting);
3737
utils.sendUsageReport(null, args, err.message, Constants.messageTypes.ERROR, utils.getErrorCodeFromErr(err));
38+
process.exitCode = Constants.ERROR_EXIT_CODE;
3839
});
3940
};

bin/commands/info.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,5 +96,6 @@ module.exports = function info(args) {
9696
logger.error(err);
9797
utils.setUsageReportingFlag(null, args.disableUsageReporting);
9898
utils.sendUsageReport(null, args, err.message, Constants.messageTypes.ERROR, utils.getErrorCodeFromErr(err));
99+
process.exitCode = Constants.ERROR_EXIT_CODE;
99100
})
100101
}

bin/commands/runs.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ module.exports = function run(args) {
189189
await utils.stopLocalBinary(bsConfig, bs_local, args);
190190

191191
utils.sendUsageReport(bsConfig, args, err, Constants.messageTypes.ERROR, 'build_failed');
192+
process.exitCode = Constants.ERROR_EXIT_CODE;
192193
});
193194
}).catch(function (err) {
194195
// Zip Upload failed | Local Start failed
@@ -200,6 +201,7 @@ module.exports = function run(args) {
200201
fileHelpers.deleteZip();
201202
utils.sendUsageReport(bsConfig, args, `${err}\n${Constants.userMessages.ZIP_UPLOAD_FAILED}`, Constants.messageTypes.ERROR, 'zip_upload_failed');
202203
}
204+
process.exitCode = Constants.ERROR_EXIT_CODE;
203205
});
204206
}).catch(function (err) {
205207
// Zipping failed
@@ -211,12 +213,14 @@ module.exports = function run(args) {
211213
} catch (err) {
212214
utils.sendUsageReport(bsConfig, args, Constants.userMessages.ZIP_DELETE_FAILED, Constants.messageTypes.ERROR, 'zip_deletion_failed');
213215
}
216+
process.exitCode = Constants.ERROR_EXIT_CODE;
214217
});
215218
}).catch(function (err) {
216219
// md5 check failed
217220
logger.error(err);
218221
logger.error(Constants.userMessages.FAILED_MD5_CHECK);
219222
utils.sendUsageReport(bsConfig, args, Constants.userMessages.MD5_CHECK_FAILED, Constants.messageTypes.ERROR, 'zip_already_uploaded_failed');
223+
process.exitCode = Constants.ERROR_EXIT_CODE;
220224
});
221225
}).catch(function (err) {
222226
// browerstack.json is not valid
@@ -230,10 +234,12 @@ module.exports = function run(args) {
230234

231235
let error_code = utils.getErrorCodeFromMsg(err);
232236
utils.sendUsageReport(bsConfig, args, `${err}\n${Constants.validationMessages.NOT_VALID}`, Constants.messageTypes.ERROR, error_code);
237+
process.exitCode = Constants.ERROR_EXIT_CODE;
233238
});
234239
}).catch(function (err) {
235240
logger.error(err);
236241
utils.setUsageReportingFlag(null, args.disableUsageReporting);
237242
utils.sendUsageReport(null, args, err.message, Constants.messageTypes.ERROR, utils.getErrorCodeFromErr(err));
243+
process.exitCode = Constants.ERROR_EXIT_CODE;
238244
});
239245
}

bin/commands/stop.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,6 @@ module.exports = function stop(args) {
9292
logger.error(err);
9393
utils.setUsageReportingFlag(null, args.disableUsageReporting);
9494
utils.sendUsageReport(null, args, err.message, Constants.messageTypes.ERROR, utils.getErrorCodeFromErr(err));
95+
process.exitCode = Constants.ERROR_EXIT_CODE;
9596
})
9697
}

bin/helpers/buildArtifacts.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ exports.downloadBuildArtifacts = async (bsConfig, buildId, args) => {
193193
messageType = Constants.messageTypes.ERROR;
194194
message = Constants.userMessages.DOWNLOAD_BUILD_ARTIFACTS_FAILED.replace('<build-id>', buildId).replace('<machine-count>', BUILD_ARTIFACTS_FAIL_COUNT);
195195
logger.error(message);
196+
process.exitCode = Constants.ERROR_EXIT_CODE;
196197
} else {
197198
messageType = Constants.messageTypes.SUCCESS;
198199
message = Constants.userMessages.DOWNLOAD_BUILD_ARTIFACTS_SUCCESS.replace('<build-id>', buildId).replace('<user-path>', process.cwd());
@@ -214,5 +215,6 @@ exports.downloadBuildArtifacts = async (bsConfig, buildId, args) => {
214215
}
215216

216217
utils.sendUsageReport(bsConfig, args, err, messageType, errorCode);
218+
process.exitCode = Constants.ERROR_EXIT_CODE;
217219
}
218220
};

bin/helpers/constants.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ const usageReportingConstants = {
188188

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

191+
const ERROR_EXIT_CODE = 1;
192+
191193
module.exports = Object.freeze({
192194
syncCLI,
193195
userMessages,
@@ -203,5 +205,6 @@ module.exports = Object.freeze({
203205
SPEC_TOTAL_CHAR_LIMIT,
204206
METADATA_CHAR_BUFFER_PER_SPEC,
205207
usageReportingConstants,
206-
LATEST_VERSION_SYNTAX_REGEX
208+
LATEST_VERSION_SYNTAX_REGEX,
209+
ERROR_EXIT_CODE
207210
});

bin/helpers/reporterHTML.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,10 @@ function generateCypressCombinationSpecReportDataWithConfigJson(combination){
277277
});
278278
combination.tests = sessionTests;
279279
resolve(combination.tests);
280-
} catch (error) { reject(error) }
280+
} catch (error) {
281+
process.exitCode = Constants.ERROR_EXIT_CODE;
282+
reject(error);
283+
}
281284
})
282285
}
283286

@@ -308,7 +311,10 @@ function generateCypressCombinationSpecReportDataWithoutConfigJson(combination){
308311
});
309312
combination.tests = sessionTests;
310313
resolve(combination.tests);
311-
} catch (error) { reject(error) }
314+
} catch (error) {
315+
process.exitCode = Constants.ERROR_EXIT_CODE;
316+
reject(error);
317+
}
312318
})
313319
}
314320

0 commit comments

Comments
 (0)