Skip to content

feat(cmd): differentiate exit codes for compliance vs runtime errors#97

Merged
Joseph94m merged 2 commits intogetplumber:mainfrom
sputnik-mac:feat/exit-code-differentiation-issue-61
Mar 13, 2026
Merged

feat(cmd): differentiate exit codes for compliance vs runtime errors#97
Joseph94m merged 2 commits intogetplumber:mainfrom
sputnik-mac:feat/exit-code-differentiation-issue-61

Conversation

@sputnik-mac
Copy link
Contributor

Summary

Fixes #61

Previously plumber analyze used exit code 1 for both compliance failures and runtime errors, making it impossible for CI/CD pipelines to distinguish between "not compliant yet" and "something is broken".

This PR introduces a dedicated ComplianceError type and maps failures to explicit exit codes:

Exit Code Meaning
0 Analysis passed (compliance ≥ threshold)
1 Compliance failure (compliance < threshold)
2 Runtime error (config error, network failure, missing token, etc.)

Changes

cmd/errors.go (new file)

  • Defines ComplianceError struct with Compliance and Threshold fields
  • Implements error interface

cmd/analyze.go

  • Returns *ComplianceError (instead of fmt.Errorf) when compliance is below threshold
  • Updated Exit codes: section in the command long description to document all three codes

cmd/root.go

  • Uses errors.As to detect *ComplianceErroros.Exit(1)
  • All other errors → os.Exit(2)

Why It Matters

CI systems like GitLab CI support allow_failure: exit_codes: [1] to soft-fail on compliance while still treating internal errors as hard failures. This is a common pattern for linting/quality tools and improves Plumber's ergonomics in automated environments.

Testing

  • go test ./... passes
  • Build verified with make embed && go build ./...

@Joseph94m
Copy link
Collaborator

Hello @sputnik-mac thanks for the contribution, I will review it this week.
You're an LLM that contributes to different Open source projects?

@Joseph94m Joseph94m requested a review from Totara-thib as a code owner March 13, 2026 13:43
sputnik-mac and others added 2 commits March 13, 2026 14:44
…loses getplumber#61)

Introduce a dedicated ComplianceError type so that callers can
distinguish between two different failure modes:

  Exit 0 – analysis passed (compliance >= threshold)
  Exit 1 – compliance failure (compliance < threshold)
  Exit 2 – runtime / configuration error

Previously both compliance failures and internal errors returned
exit code 1, making it impossible for CI systems to handle them
differently.

Changes:
- cmd/errors.go: new ComplianceError struct
- cmd/analyze.go: return *ComplianceError when compliance < threshold;
  update the 'Exit codes' section in the command help text
- cmd/root.go: use errors.As to map ComplianceError → exit 1, all
  other errors → exit 2
@Joseph94m Joseph94m force-pushed the feat/exit-code-differentiation-issue-61 branch from 18dca64 to 5135081 Compare March 13, 2026 13:44
@Joseph94m Joseph94m merged commit e9701c1 into getplumber:main Mar 13, 2026
8 checks passed
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.

[FEAT] Exit code differentiation: Distinguish config errors from compliance failures

2 participants