Skip to content
This repository has been archived by the owner on Jul 9, 2019. It is now read-only.

Commit

Permalink
Make all command line utilities fail when there was an unhandled error
Browse files Browse the repository at this point in the history
This ensures that the command line utilities are returning a non-zero
exit code whenever something failed.
  • Loading branch information
xdarklight committed Mar 19, 2016
1 parent 3290a6e commit 8524565
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions add-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
2 changes: 2 additions & 0 deletions add-incremental.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions disable-build.js
Original file line number Diff line number Diff line change
@@ -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.');
Expand All @@ -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: [
Expand Down
3 changes: 3 additions & 0 deletions generate-website.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {

Expand Down
3 changes: 3 additions & 0 deletions get-sourcecode-timestamp.js
Original file line number Diff line number Diff line change
@@ -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: [
Expand Down
3 changes: 3 additions & 0 deletions get-target-file-zipnames.js
Original file line number Diff line number Diff line change
@@ -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.');
Expand All @@ -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;

Expand Down
8 changes: 8 additions & 0 deletions utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.