Skip to content

Commit

Permalink
[refactor] Refactor error handling in jitsu to use forza instead …
Browse files Browse the repository at this point in the history
…of `haibu`.
  • Loading branch information
indexzero committed Aug 30, 2013
1 parent 738f2f8 commit fe03793
Showing 1 changed file with 69 additions and 47 deletions.
116 changes: 69 additions & 47 deletions lib/jitsu.js
Expand Up @@ -294,8 +294,50 @@ jitsu.setup = function (callback) {
//
jitsu.showError = function (command, err, shallow, skip) {
var username,
display,
errors,
stack;

//
// ### function unknownError(message, stack)
// Displays an unknown error by dumping the call `stack`
// and a given `message`.
//
function unknownError(message, stack) {
jitsu.log.error(message);
stack.split('\n').forEach(function (line) {
jitsu.log.error(line);
})
}

//
// ### function solenoidError(display)
// Displays a "solenoid" error.
//
function solenoidError(display) {
jitsu.log.error('Error starting application. This is usually a user error.');
display.solenoid.split('\n').forEach(function (line) {
jitsu.log.error(line);
});
}

//
// ### function appError(display)
// Displays an "application" error.
//
function appError(display) {
if (display.output) {
jitsu.log.error('Error output from application. This could be a user error.');
display.output.split('\n').forEach(function (line) {
jitsu.log.error(line);
})
}

return !display.solenoid
? unknownError(display.message, display.stack)
: solenoidError(display);
}

if (err.statusCode === 403) {
//jitsu.log.error('403 ' + err.result.error);
}
Expand All @@ -309,7 +351,6 @@ jitsu.showError = function (command, err, shallow, skip) {
}
else if (!skip) {
jitsu.log.error('Error running command ' + command.magenta);

if (!jitsu.config.get('nolog')) {
jitsu.logFile.log(err);
}
Expand All @@ -319,59 +360,39 @@ jitsu.showError = function (command, err, shallow, skip) {
}

if (err.result) {
if (err.result.error) {
jitsu.log.error(err.result.error);
jitsu.log.error('');
jitsu.log.error('There was an error while attempting to start the app.');
if (err.result.message) {
jitsu.log.error(err.result.message);
}

if (err.result.result && err.result.result.error) {
if (err.result.result.error.stderr || err.result.result.error.stdout) {
jitsu.log.error('');
jitsu.log.error('There was an error while attempting to start the app');
jitsu.log.error(err.result.result.error.message);
if (err.result.result.error.blame) {
jitsu.log.error(err.result.result.error.blame.message);
jitsu.log.error('');
jitsu.log.error('This type of error is usually a ' + err.result.result.error.blame.type + ' error.');
}

jitsu.log.error('Error output from app:');
jitsu.log.error('');
if (err.result.result.error.stdout) {
err.result.result.error.stdout.split('\n').forEach(function (line) {
jitsu.log.error(line);
});
}

if (err.result.result.error.stderr) {
err.result.result.error.stderr.split('\n').forEach(function (line) {
jitsu.log.error(line);
});
}
if (err.result.errors && Array.isArray(err.result.errors)) {
errors = {
connection: err.result.errors.filter(function (err) {
return err.blame === 'connection';
}),
application: err.result.errors.filter(function (err) {
return err.blame === 'application';
}),
solenoid: err.result.errors.filter(function (err) {
return err.blame === 'solenoid';
})
};

if (errors.application.length) {
return appError(errors.application[0]);
}
else if (errors.solenoid.length) {
return solenoidError(errors.solenoid[0])
}
else if (err.result.result.error.stack) {
jitsu.log.error('There was an error while attempting to deploy the app');
jitsu.log.error('');
jitsu.log.error(err.result.result.error.message);

if (err.result.result.error.blame) {
jitsu.log.error(err.result.result.error.blame.message);
jitsu.log.error('');
jitsu.log.error('This type of error is usually a ' + err.result.result.error.blame.type + ' error.');
}

jitsu.log.error('Error output from Haibu:');
jitsu.log.error('');
stack = err.result.result.error.result || err.result.result.error.stack;
stack.split('\n').forEach(function (line) {
jitsu.log.error(line);
});
return errors.connection.length
? unknownError('Error contacting drone(s):', errors.connection[0].stack)
: unknownError('Error returned from Nodejitsu:', errors[0].stack);
}
}
else if (err.result.stack) {
jitsu.log.warn('Error returned from Nodejitsu');
err.result.stack.split('\n').forEach(function (line) {
jitsu.log.error(line);
});
unknownError('Error returned from Nodejitsu:', err.result.stack);
}
}
else {
Expand All @@ -393,6 +414,7 @@ jitsu.showError = function (command, err, shallow, skip) {
}
}
}

jitsu.log.help("For help with this error contact Nodejitsu Support:");
jitsu.log.help(" webchat: <http://webchat.nodejitsu.com/>");
jitsu.log.help(" irc: <irc://chat.freenode.net/#nodejitsu>");
Expand Down

0 comments on commit fe03793

Please sign in to comment.