Permalink
Browse files

Make all command line utilities fail when there was an unhandled error

This ensures that the command line utilities are returning a non-zero
exit code whenever something failed.
  • Loading branch information...
1 parent 3290a6e commit 85245650c023d2c29021da6b130e963516acf6ac @xdarklight committed Mar 19, 2016
Showing with 24 additions and 0 deletions.
  1. +2 −0 add-build.js
  2. +2 −0 add-incremental.js
  3. +3 −0 disable-build.js
  4. +3 −0 generate-website.js
  5. +3 −0 get-sourcecode-timestamp.js
  6. +3 −0 get-target-file-zipnames.js
  7. +8 −0 utils.js
View
@@ -85,6 +85,8 @@ if (buildInfo.changelogfile) {
changelog = fs.readFileSync(buildInfo.changelogfile, 'utf-8');
}
+utils.rethrowUnhandledPromiseRejections();
+
models.sequelize.sync().then(function() {
models.RomVariant.find({
include: [
View
@@ -54,6 +54,8 @@ var findRomWithTargetFilesZipName = function(targetFilesZipName, subdirectory) {
});
}
+utils.rethrowUnhandledPromiseRejections();
+
models.sequelize.sync().then(function() {
findRomWithTargetFilesZipName(buildInfo.from_target_files, buildInfo.subdirectory).then(function(sourceRom) {
if (sourceRom) {
View
@@ -1,5 +1,6 @@
var Troll = require('troll-opt').Troll;
var models = require('./models/');
+var utils = require('./utils.js');
var buildInfo = (new Troll()).options(function(troll) {
troll.banner('Marks a build as disabled so it cannot be downloaded anymore.');
@@ -9,6 +10,8 @@ var buildInfo = (new Troll()).options(function(troll) {
troll.opt('disable_incrementals', 'Disables the incrementals for this rom also.', { type: 'boolean' });
});
+utils.rethrowUnhandledPromiseRejections();
+
models.sequelize.sync().then(function() {
models.Rom.findAll({
include: [
View
@@ -5,6 +5,9 @@ var wintersmith = require('wintersmith');
var config = require('config').Website;
var models = require('./models/');
var ResultConverter = require('./result-converter.js');
+var utils = require('./utils.js');
+
+utils.rethrowUnhandledPromiseRejections();
models.sequelize.sync().then(function() {
@@ -1,12 +1,15 @@
var Troll = require('troll-opt').Troll;
var models = require('./models/');
+var utils = require('./utils.js');
var buildInfo = (new Troll()).options(function(troll) {
troll.banner('Outputs the newest source-code as ISO-8601 string for the given device / subdirectory.');
troll.opt('device', 'The device ID.', { type: 'string', required: true });
troll.opt('subdirectory', 'The subdirectory from which the file can be downloaded.', { type: 'string' });
});
+utils.rethrowUnhandledPromiseRejections();
+
models.sequelize.sync().then(function() {
models.Rom.find({
include: [
@@ -1,5 +1,6 @@
var Troll = require('troll-opt').Troll;
var models = require('./models/');
+var utils = require('./utils.js');
var buildInfo = (new Troll()).options(function(troll) {
troll.banner('Outputs all target-files zip names (one per line) for all builds that match the given device / subdirectory.');
@@ -10,6 +11,8 @@ var buildInfo = (new Troll()).options(function(troll) {
var minDate = new Date(-8640000000000000);
+utils.rethrowUnhandledPromiseRejections();
+
models.sequelize.sync().then(function() {
var startTimestamp;
View
@@ -5,3 +5,11 @@ module.exports.toDate = function(unixTimestampObject) {
module.exports.toUnixTimestamp = function(date) {
return new Date(date).getTime() / 1000;
}
+
+module.exports.rethrowUnhandledPromiseRejections = function() {
+ // http://bluebirdjs.com/docs/api/error-management-configuration.html#global-rejection-events
+ // https://github.com/sequelize/sequelize/issues/5576
+ process.on("unhandledRejection", function(exception, promise) {
+ throw exception;
+ });
+}

0 comments on commit 8524565

Please sign in to comment.