Skip to content

Commit

Permalink
improved error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
pstadler committed Jun 8, 2014
1 parent 0db9fd1 commit 6438a61
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 43 deletions.
9 changes: 0 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,6 @@ succeeded.

Whether the flightplan is aborted or not.

### flightplan.abort()

Calling this method will abort the flightplan and prevent any further
flights from being executed.

```javascript
plan.abort();
```

<!-- End lib/flightplan.js -->

<!-- Start lib/transport/index.js -->
Expand Down
17 changes: 10 additions & 7 deletions lib/flight.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ Flight.prototype = {
},

abort: function(msg) {
this.status.aborted = true;
this.status.crashRecordings = msg;
this.flightplan.abort();
throw new Error(msg);
},

Expand All @@ -45,15 +48,15 @@ Flight.prototype = {
try {
this.fn(transport);
} catch(e) {
this.status.aborted = true;
this.status.crashRecordings = e.message || null;
this.flightplan.abort();
}
transport.close();
this.abort(e.message);
} finally {
transport.close();

this.status.executionTime = process.hrtime(t);

this.status.executionTime = process.hrtime(t);
return future.return();
}

return future.return();
}.bind(this)).run();

return future;
Expand Down
18 changes: 3 additions & 15 deletions lib/flightplan.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ Flightplan.prototype = {
return this;
},


/**
* Whether the flightplan is aborted or not.
*
Expand All @@ -237,16 +236,6 @@ Flightplan.prototype = {
return this.status.aborted;
},

/**
* Calling this method will abort the flightplan and prevent any further
* flights from being executed.
*
* ```javascript
* plan.abort();
* ```
*
* @method abort()
*/
abort: function() {
this.status.aborted = true;
},
Expand Down Expand Up @@ -293,12 +282,11 @@ Flightplan.prototype = {

var status = flight.getStatus()
, flightNumber = this.logger.format('%s/%s', i+1, len).magenta
, executionTime = prettyTime(status.executionTime).magenta
, crashReason = !status.crashRecordings
? ''
: this.logger.format('when %s', status.crashRecordings);
, executionTime = prettyTime(status.executionTime).magenta;

if(flight.isAborted()) {
var crashReason = !status.crashRecordings ? ''
: this.logger.format('when %s', status.crashRecordings);
this.logger.error('Flight'.error, flightNumber, 'aborted after'.error
, executionTime, crashReason);
this.logger.space();
Expand Down
18 changes: 8 additions & 10 deletions lib/remote.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ function RemoteFlight(flightplan, fn) {
RemoteFlight.super_.call(this, flightplan, SSHTransport, fn);

if(!this.flightplan.briefing()) {
this.logger.error("You can't do remote flights without a briefing.");
this.flightplan.abort();
this.abort("You can't do remote flights without a briefing.");
}
}

Expand All @@ -26,16 +25,15 @@ RemoteFlight.prototype.__start = function() {
try {
flight.fn(transport);
} catch(e) {
this.status.aborted = true;
this.status.crashRecordings = e.message || null;
this.flightplan.abort();
}
transport.close();
this.abort(e.message);
} finally {
transport.close();

flight.status.executionTime = process.hrtime(t);
this.status.executionTime = flight.status.executionTime;
flight.status.executionTime = process.hrtime(t);
this.status.executionTime = flight.status.executionTime;

return future.return();
return future.return();
}
}.bind(this)).run();

return future;
Expand Down
3 changes: 2 additions & 1 deletion lib/transport/shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ ShellTransport.prototype.__exec = function(cmd, args, options) {
this.logger.warn(this.logger.format('failed safely').warn, 'with exit code:', ret.code);
} else {
this.logger.error(this.logger.format('failed').error, 'with exit code:', ret.code);
fiber.throwInto(new Error(this.logger.format('`%s` failed on localhost', cmd.white)));
fiber.throwInto(new Error(this.logger.format('`%s` failed on %s'
, cmd.white, 'localhost'.warn)));
}
fiber.run(ret);
}.bind(this));
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "flightplan",
"description": "Library for streamlining application deployment or systems administration tasks",
"version": "0.3.3",
"version": "0.3.4",
"author": "Patrick Stadler <patrick.stadler@gmail.com>",
"keywords": [
"deploy",
Expand Down

0 comments on commit 6438a61

Please sign in to comment.