From 0859439f0a00208dd8079e39d3c39db9fa69bb20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=89=AF?= <841369634@qq.com> Date: Wed, 16 Oct 2024 16:46:26 +0800 Subject: [PATCH] =?UTF-8?q?bugfix:=20=E4=BF=AE=E5=A4=8D=E8=AE=B0=E5=BD=95s?= =?UTF-8?q?hell=E5=91=BD=E4=BB=A4=E6=97=A5=E5=BF=97=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E7=BA=BF=E7=A8=8B=E5=8D=A1=E6=AD=BB=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/src/shell/shell.js | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/packages/core/src/shell/shell.js b/packages/core/src/shell/shell.js index 0c5790c..f421df1 100644 --- a/packages/core/src/shell/shell.js +++ b/packages/core/src/shell/shell.js @@ -80,7 +80,7 @@ function _childExec (composeCmds, options = {}) { childProcess.exec(composeCmds, options, function (error, stdout, stderr) { if (error) { if (options.printErrorLog !== false) { - log.error('cmd 命令执行错误:\n===>\ncommands:', composeCmds, '\n error:', error, '\n stdout:', stdout, '\n stderr:', stderr, '\n<===') + log.error('cmd 命令执行错误:\n===>\ncommands:', composeCmds, '\n error:', error, '\n<===') } reject(new Error(stderr)) } else { @@ -105,7 +105,7 @@ function childExec (composeCmds, options = {}) { // console.log('------', decoder.decode(stderr)) const message = iconv.decode(Buffer.from(stderr, binaryEncoding), encoding) if (options.printErrorLog !== false) { - log.error('cmd 命令执行错误:\n------------------------------\ncommands:', composeCmds, '\n message:', message, '\n error:', error, '\n stdout:', stdout, '\n stderr:', stderr, '\n------------------------------') + log.error('cmd 命令执行错误:\n------------------------------\ncommands:', composeCmds, '\n message:', message, '\n error:', error, '\n------------------------------') } reject(new Error(message)) } else { @@ -154,15 +154,20 @@ async function execute (executor, args) { async function execFile (file, args, options) { return new Promise((resolve, reject) => { - _execFile(file, args, options, (err, stdout) => { - if (err) { - log.error('文件执行出错:', file, err) - reject(err) - return - } - log.debug('执行成功:', stdout) - resolve(stdout) - }) + try { + _execFile(file, args, options, (err, stdout) => { + if (err) { + log.error('文件执行出错:', file, err) + reject(err) + return + } + log.debug('文件执行成功:', file) + resolve(stdout) + }) + } catch (e) { + log.error('文件执行出错:', file, e) + reject(e) + } }) }