[bug] Fix process exiting with status 0 on collection failures (#11)#12
Merged
Conversation
Replace `return` with `os.Exit(1)` in all error branches of `main()` (credentials, LDAP session creation, connect, query, JSON export, file write, and the failed-connection else branch) so callers — CI, scripts, orchestration — can detect a failed collection through the exit status.
7d78a30 to
8aac51b
Compare
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.
Linked Issue
Closes #11
Root Cause
Every error branch in
main.go'smain()aborted withreturnafter logging a warning. Returning frommainyields exit code0, so an unreachable DC, a bad credential, a failed LDAP query, a JSON serialization error, or a failed file write all looked like a clean run to any caller. Automated pipelines that relied on the exit status to gate downstream work would silently proceed on stale or missing output.Fix Description
Replace
returnwithos.Exit(1)in each of the seven error branches inmain():elsebranch whereConnect()reportssuccess == falsewithout an error (L141)The success path is untouched, so a normal run still falls off the bottom of
mainand exits0. Addingos.Exit(1)to the finalelsebranch fixes a pre-existing gap there where the program would also exit cleanly even when the LDAP connection reported failure without an explicit Go error.How Verified
Runtime:
Before the fix the same command exited with
0.Test Coverage
None: the change is a control-flow swap from
returntoos.Exit(1)in seven well-isolated branches; there is no test harness in the repository, and the behavior is trivially verifiable from a shell.Scope of Change
main.goRisk and Rollout
Existing scripts that explicitly ignore the exit status are unaffected. Scripts that previously assumed success because the exit code was always
0will now see failures surface; this is the intended improvement.