Update main.js code flow so proxy always gets stopped + add comment on why exit status is handled in bin/aikido-(tool).js

This commit is contained in:
Sander Declerck 2025-10-06 13:47:38 +02:00
parent ccaa7934ee
commit 3ef4ed8bad
No known key found for this signature in database
2 changed files with 30 additions and 16 deletions

View file

@ -16,16 +16,17 @@ export async function main(args) {
args = initializeCliArguments(args);
if (shouldScanCommand(args)) {
await scanCommand(args);
const resultCode = await scanCommand(args);
// Returning the exit code back to the caller allows the promise
// to be awaited in the bin files and return the correct exit code
if (resultCode !== 0) {
return resultCode;
}
} catch (error) {
ui.writeError("Failed to check for malicious packages:", error.message);
process.exit(1);
}
var result = await getPackageManager().runCommand(args);
await proxy.stopServer();
proxy.verifyNoMaliciousPackages();
ui.emptyLine();
@ -35,5 +36,16 @@ export async function main(args) {
)} Safe-chain: Command completed, no malicious packages found.`
);
// Returning the exit code back to the caller allows the promise
// to be awaited in the bin files and return the correct exit code
return result.status;
} catch (error) {
ui.writeError("Failed to check for malicious packages:", error.message);
// Returning the exit code back to the caller allows the promise
// to be awaited in the bin files and return the correct exit code
return 1;
} finally {
await proxy.stopServer();
}
}

View file

@ -62,9 +62,11 @@ export async function scanCommand(args) {
if (!audit || audit.isAllowed) {
spinner.stop();
return 0;
} else {
printMaliciousChanges(audit.disallowedChanges, spinner);
await onMalwareFound();
return 1;
}
}