diff --git a/lib/util/exec/common.spec.ts b/lib/util/exec/common.spec.ts index 16f86685d4c4ce..19f1bb621ece25 100644 --- a/lib/util/exec/common.spec.ts +++ b/lib/util/exec/common.spec.ts @@ -184,7 +184,7 @@ describe('util/exec/common', () => { exec(cmd, partial({ encoding: 'utf8' })) ).rejects.toMatchObject({ cmd, - message: 'Process exited with exit code "1"', + message: `Command failed: ${cmd}\n${stderr}`, exitCode, stderr, }); @@ -200,7 +200,7 @@ describe('util/exec/common', () => { ).rejects.toMatchObject({ cmd, signal: exitSignal, - message: 'Process signaled with "SIGTERM"', + message: `Command failed: ${cmd}\nInterrupted by ${exitSignal}`, }); }); diff --git a/lib/util/exec/common.ts b/lib/util/exec/common.ts index d0a5aa156f5c79..5287586355a878 100644 --- a/lib/util/exec/common.ts +++ b/lib/util/exec/common.ts @@ -76,6 +76,7 @@ export function exec(cmd: string, opts: RawExecOptions): Promise { // handle process events cp.on('error', (error) => { kill(cp, 'SIGTERM'); + // rethrowing, use originally emitted error message reject(new ExecError(error.message, rejectInfo(), error)); }); @@ -83,16 +84,23 @@ export function exec(cmd: string, opts: RawExecOptions): Promise { if (NONTERM.includes(signal)) { return; } - if (signal) { - const message = `Process signaled with "${signal}"`; kill(cp, signal); - reject(new ExecError(message, { ...rejectInfo(), signal })); + reject( + new ExecError(`Command failed: ${cmd}\nInterrupted by ${signal}`, { + ...rejectInfo(), + signal, + }) + ); return; } if (code !== 0) { - const message = `Process exited with exit code "${code}"`; - reject(new ExecError(message, { ...rejectInfo(), exitCode: code })); + reject( + new ExecError(`Command failed: ${cmd}\n${stringify(stderr)}`, { + ...rejectInfo(), + exitCode: code, + }) + ); return; } resolve({