Skip to content

feat: add structured exit codes for CI/CD scripting#66

Merged
mostafa merged 1 commit intomainfrom
feat/structured-exit-codes
May 2, 2026
Merged

feat: add structured exit codes for CI/CD scripting#66
mostafa merged 1 commit intomainfrom
feat/structured-exit-codes

Conversation

@mostafa
Copy link
Copy Markdown
Member

@mostafa mostafa commented May 2, 2026

Summary

  • Introduce categorized exit codes (0 SUCCESS, 1 FINDINGS, 2 RULE_ERROR, 3 CONFIG_ERROR) so CI/CD pipelines can distinguish "the tool found something" from "the tool broke."
  • Add eval --fail-on-detection flag to exit 1 when any detection or correlation fires.
  • Add lint --fail-level <error|warning|info> flag to control the severity threshold that triggers a non-zero exit.
  • Replace all blanket process::exit(1) calls across every subcommand (eval, lint, validate, convert, parse) and the daemon with the appropriate categorized code.

Test results

All tests verified manually on feat/structured-exit-codes @ 9453f86.

Automated

  • cargo clippy --workspace --all-targets --all-features -- -D warnings -- clean
  • cargo test --workspace -- all passing

Manual: eval --fail-on-detection

Test Command Expected Actual
Match + flag rsigma eval --fail-on-detection -r rule.yml -e '{"CommandLine":"mimikatz.exe …"}' exit 1 exit 1
No match + flag rsigma eval --fail-on-detection -r rule.yml -e '{"CommandLine":"whoami"}' exit 0 exit 0
Match, no flag rsigma eval -r rule.yml -e '{"CommandLine":"mimikatz.exe …"}' exit 0 exit 0
Match + flag + @file rsigma eval --fail-on-detection -r rule.yml -e @match.json exit 1 exit 1

Manual: lint --fail-level

Test Command Expected Actual
Default (error) rsigma lint rule.yml (has warnings + infos, no errors) exit 0 exit 0
--fail-level warning rsigma lint --fail-level warning rule.yml exit 1 exit 1
--fail-level info rsigma lint --fail-level info rule.yml exit 1 exit 1

Manual: categorized error codes

Test Command Expected Actual
Bad rule syntax rsigma eval -r bad_syntax.yml -e '{…}' exit 2 (RULE_ERROR) exit 2
Nonexistent pipeline rsigma eval -r rule.yml -p nonexistent.yml -e '{…}' exit 3 (CONFIG_ERROR) exit 3

Replace blanket `process::exit(1)` with categorized codes so callers
can distinguish findings from errors:

  0  SUCCESS       -- ran OK, nothing actionable
  1  FINDINGS      -- detections fired or lint findings above threshold
  2  RULE_ERROR    -- rule parse / compile failure
  3  CONFIG_ERROR  -- bad pipeline, invalid argument, misconfiguration

New CLI flags:
  eval --fail-on-detection  exit 1 when any detection fires
  lint --fail-level <level> exit 1 at error (default), warning, or info
@mostafa mostafa merged commit 975f47d into main May 2, 2026
8 checks passed
@mostafa mostafa deleted the feat/structured-exit-codes branch May 2, 2026 19:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant