Catch command for in-shell errors

This commit is contained in:
Webber 2020-05-21 20:40:03 +02:00 committed by Webber Takken
parent 8c9ff3249e
commit 054c6bfab3

View File

@ -19,8 +19,7 @@ class System {
},
};
const exitCode = await exec(command, arguments_, { silent: true, listeners, ...options });
const showOutput = () => {
if (debug !== '') {
core.debug(debug);
}
@ -32,14 +31,28 @@ class System {
if (error !== '') {
core.warning(error);
}
};
if (exitCode !== 0) {
let argumentsString = '';
const throwErrorShowing = (message) => {
let commandAsString = command;
if (Array.isArray(arguments_)) {
argumentsString += ` ${arguments_.join(' ')}`;
commandAsString += ` ${arguments_.join(' ')}`;
} else if (typeof arguments_ === 'string') {
commandAsString += ` ${arguments_}`;
}
throw new Error(`Failed to run "${command}${argumentsString}".\n ${error}`);
throw new Error(`Failed to run "${commandAsString}".\n ${message}`);
};
try {
const exitCode = await exec(command, arguments_, { silent: true, listeners, ...options });
showOutput();
if (exitCode !== 0) {
throwErrorShowing(error);
}
} catch (inCommandError) {
showOutput();
throwErrorShowing(inCommandError);
}
return result;