From 8aac51b09299196ba87624cf4ad6ec5c180172a3 Mon Sep 17 00:00:00 2001 From: "Remi GASCOU (Podalirius)" <79218792+p0dalirius@users.noreply.github.com> Date: Thu, 21 May 2026 10:28:19 +0200 Subject: [PATCH] Fix process exiting with status 0 on collection failures (#11) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- main.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index 5f859f9..d47a764 100755 --- a/main.go +++ b/main.go @@ -74,7 +74,7 @@ func main() { creds, err := credentials.NewCredentials(authDomain, authUsername, authPassword, authHashes) if err != nil { logger.Warn(fmt.Sprintf("Error creating credentials: %s", err)) - return + os.Exit(1) } // Parsing input values for Distinguished Name @@ -89,12 +89,12 @@ func main() { ldapSession, err := ldap.NewSession(domainController, ldapPort, creds, useLdaps, useKerberos) if err != nil { logger.Warn(fmt.Sprintf("Error creating LDAP session: %s", err)) - return + os.Exit(1) } success, err := ldapSession.Connect() if err != nil { logger.Warn(fmt.Sprintf("Error connecting to LDAP: %s", err)) - return + os.Exit(1) } if success { @@ -108,7 +108,7 @@ func main() { ldapResults, err := ldapSession.QueryWholeSubtree("", query, attributes) if err != nil { logger.Warn(fmt.Sprintf("Error querying LDAP: %s", err)) - return + os.Exit(1) } og := gopengraph.NewOpenGraph("KeyCredentialBase") @@ -119,12 +119,12 @@ func main() { jsonData, err := og.ExportJSON(false) if err != nil { logger.Warn(fmt.Sprintf("Error serializing graph to JSON: %s", err)) - return + os.Exit(1) } err = os.WriteFile(outputFile, []byte(jsonData), 0600) if err != nil { logger.Warn(fmt.Sprintf("Error writing graph to file %s: %s", outputFile, err)) - return + os.Exit(1) } logger.Info(fmt.Sprintf("Graph exported to file: %s", outputFile)) @@ -132,5 +132,6 @@ func main() { if debug { logger.Warn("Error: Could not create ldapSession.") } + os.Exit(1) } }