check exit code on close

This commit is contained in:
oleg 2014-12-04 23:09:43 +03:00
parent 75734b8d9a
commit bdce719b4e

View File

@ -31,17 +31,16 @@ Command.prototype.run = function(params, callback) {
stdout += data;
});
cmd.stderr.on('data', function(data) {
callback(new Error('Scm outputs to stderr: ' + data));
callback(new Error('Spawned command outputs to stderr: ' + data));
cmd.kill();
});
cmd.on('exit', function(code) {
if (code !== 0) callback(new Error(
'Spawned command exits with non-zero code: ' + code
));
});
// TODO; callback should be called only once (port once from underscore)
cmd.on('close', function() {
callback(null, stdout);
cmd.on('close', function(code) {
var err = null;
if (code !== 0) err = new Error(
'Spawned command exits with non-zero code: ' + code
);
callback(err, stdout);
});
return cmd;
};