convert more execSync to async

This commit is contained in:
Girish Ramakrishnan
2024-02-20 23:09:49 +01:00
parent b51071155a
commit 9b94cf18d0
15 changed files with 71 additions and 72 deletions

View File

@@ -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);
});