fix: fail the scan when a requested -conf cannot be written - #11
Merged
Conversation
writeConfFile printed both of its failures and returned, so runScanCmd finished with nil and the process exited 0 even though the requested config was never created. It now returns an error, which runScanCmd propagates after the report is written. Fixes vernette#6
Owner
|
Thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #6.
writeConfFiledid not return an error: it printed both of its failures to stderr and returned early, sorunScanCmdreturnedniland the process exited 0 even though the requested config was never created.What changed
writeConfFilenow returns an error andrunScanCmdpropagates it. Both failures are covered: the write itself, and having no durable endpoint to write a config for.The error is no longer printed where it happens:
mainalready renders every command error through the sameerrPal.failbeforeos.Exit(1), so keeping both would print the line twice. That also matchessetupScan,validateThresholdandrunRegisterCmd, which return their errors without printing them.The failure is held in a local and returned at the end rather than early, so the report file is still written: the scan itself succeeded, only the exit status should change. All three exits after the config step propagate it.
Out of scope
A failing report write stays non-fatal: it is written unconditionally under a generated name, so making it fatal would change the exit status of runs that never asked for a file.
printBeststill callsos.Exit(1)from inside itself on the same condition: same class of problem, separate change.Test
TestWriteConfFilecovers a successful write, an unwritable path, and a run with nothing but torn-down endpoints, asserting the error and that no config file is left behind. The unwritable path is a missing parent directory rather than a read-only one, which root walks straight through. With bothreturns changed back tonil, the test fails on both assertions.