Skip to content

Commit

Permalink
Merge pull request #466 from nodejitsu/forza-errors
Browse files Browse the repository at this point in the history
Forza errors
  • Loading branch information
jcrugzz committed Sep 9, 2013
2 parents c82fc55 + 90f5ec9 commit 76b0234
Showing 1 changed file with 73 additions and 52 deletions.
125 changes: 73 additions & 52 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 could be 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 is usually 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,69 +351,41 @@ 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);
}

if (err.message) {
jitsu.log.error(err.message);
}

if (err.result) {
if (err.result.error) {
jitsu.log.error(err.result.error);
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 (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);
});
else if (errors.solenoid.length) {
return solenoidError(errors.solenoid[0])
}

return errors.connection.length
? unknownError('Error contacting drone(s):', errors.connection[0].stack)
: unknownError('Error returned from Nodejitsu:', err.result.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);
});
return unknownError('Error returned from Nodejitsu:', err.result.stack);
}
}
else {
Expand All @@ -390,9 +404,16 @@ jitsu.showError = function (command, err, shallow, skip) {
jitsu.log.error(trace);
});
}

return;
}
}

if (err.message) {
jitsu.log.error(err.message);
}
}

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 76b0234

Please sign in to comment.