convert more execSync to async
This commit is contained in:
17
src/shell.js
17
src/shell.js
@@ -30,13 +30,16 @@ function exec(tag, cmd, options, callback) {
|
||||
debug(`${tag} exec: ${cmd}`);
|
||||
|
||||
child_process.exec(cmd, options, function (error, stdout, stderr) {
|
||||
const stdoutResult = stdout ? stdout.toString('utf8') : null;
|
||||
const stderrResult = stderr ? stderr.toString('utf8') : null;
|
||||
let e = null;
|
||||
if (error) {
|
||||
e = new BoxError(BoxError.SHELL_ERROR, `${tag} errored with code ${error.code} message ${error.message}`);
|
||||
e.stdout = stdout; // when promisified, this is the way to get stdout
|
||||
e.stderr = stderr; // when promisified, this is the way to get stderr
|
||||
|
||||
if (error) error.stdout = stdoutResult; // when promisified, this is the way to get stdout
|
||||
if (error) error.stderr = stderrResult; // when promisified, this is the way to get stderr
|
||||
debug(e.message);
|
||||
}
|
||||
|
||||
callback(error, stdoutResult);
|
||||
callback(e, stdout);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -73,7 +76,7 @@ function spawn(tag, file, args, options, callback) {
|
||||
if (code || signal) debug(tag + ' code: %s, signal: %s', code, signal);
|
||||
if (code === 0) return callback(null, stdoutResult);
|
||||
|
||||
let e = new BoxError(BoxError.SPAWN_ERROR, `${tag} exited with code ${code} signal ${signal}`);
|
||||
let e = new BoxError(BoxError.SHELL_ERROR, `${tag} exited with code ${code} signal ${signal}`);
|
||||
e.code = code;
|
||||
e.signal = signal;
|
||||
callback(e);
|
||||
@@ -81,7 +84,7 @@ function spawn(tag, file, args, options, callback) {
|
||||
|
||||
cp.on('error', function (error) {
|
||||
debug(tag + ' code: %s, signal: %s', error.code, error.signal);
|
||||
let e = new BoxError(BoxError.SPAWN_ERROR, `${tag} errored with code ${error.code} message ${error.message}`);
|
||||
let e = new BoxError(BoxError.SHELL_ERROR, `${tag} errored with code ${error.code} message ${error.message}`);
|
||||
callback(e);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user