Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly handle errors #135

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions lib/Local.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ function Local(){
fs.unlinkSync(that.binaryPath);
delete(that.binaryPath);
that.start(options, callback);
return;
} else {
callback(new LocalError(error.toString()));
}
return;
}

var data = {};
Expand All @@ -106,7 +106,7 @@ function Local(){
else if(stderr)
data = JSON.parse(stderr);
else
callback(new LocalError('No output received'));
return callback(new LocalError('No output received'));

if(data['state'] != 'connected'){
callback(new LocalError(data['message']['message']));
Expand All @@ -123,10 +123,10 @@ function Local(){
return this.pid && running(this.pid) && this.isProcessRunning;
};

this.stop = function (callback) {
this.stop = function(callback) {
if(!this.pid) return callback();
this.killAllProcesses(function(error){
if(error) callback(new LocalError(error.toString()));
if(error) return callback(new LocalError(error.toString()));
callback();
});
};
Expand Down Expand Up @@ -316,6 +316,7 @@ function Local(){

this.killAllProcesses = function(callback){
psTree(this.pid, (err, children) => {
if(err) return callback(err);
var childPids = children.map(val => val.PID);
var killChecker = setInterval(() => {
if(childPids.length === 0) {
Expand Down