mirror of
https://github.com/AikidoSec/safe-chain.git
synced 2026-05-26 12:10:49 +00:00
Exit installation when detecting changes failed due to non-zero exit code in dry-run
This commit is contained in:
parent
f7589160af
commit
528a60c166
5 changed files with 169 additions and 10 deletions
|
|
@ -37,10 +37,17 @@ function checkChangesWithDryRun(args) {
|
|||
|
||||
// Dry-run can return a non-zero status code in some cases
|
||||
// e.g., when running "npm audit fix --dry-run", it returns exit code 1
|
||||
// when there are vulnurabilities that can be fixed.
|
||||
// when there are vulnerabilities that can be fixed.
|
||||
if (dryRunOutput.status !== 0 && !doesCommandReturnNonZero(args)) {
|
||||
throw new Error(
|
||||
`Dry-run command failed with exit code ${dryRunOutput.status} and output:\n${dryRunOutput.output}`
|
||||
);
|
||||
}
|
||||
|
||||
if (dryRunOutput.status !== 0 && !dryRunOutput.output) {
|
||||
ui.writeError("Detecting changes failed.");
|
||||
return [];
|
||||
throw new Error(
|
||||
`Dry-run command failed with exit code ${dryRunOutput.status} and produced no output.`
|
||||
);
|
||||
}
|
||||
|
||||
const parsedOutput = parseDryRunOutput(dryRunOutput.output);
|
||||
|
|
@ -48,3 +55,11 @@ function checkChangesWithDryRun(args) {
|
|||
// reverse the array to have the top-level packages first
|
||||
return parsedOutput.reverse();
|
||||
}
|
||||
|
||||
function doesCommandReturnNonZero(args) {
|
||||
if (args.length < 2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return args[0] === "audit" && args[1] === "fix";
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue