Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -935,10 +935,11 @@ export PLUMBER_NO_UPDATE_CHECK=1

### Exit Codes

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

### `plumber config generate`

Expand Down
5 changes: 3 additions & 2 deletions cmd/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ Optional flags:

Exit codes:
0 Analysis passed (compliance >= threshold)
1 Analysis failed (compliance < threshold or error occurred)
1 Compliance failure (compliance < threshold)
2 Runtime error (configuration error, network failure, missing token, etc.)

Examples:
# Set token via environment variable
Expand Down Expand Up @@ -403,7 +404,7 @@ func runAnalyze(cmd *cobra.Command, args []string) error {

// Check compliance against threshold
if compliance < threshold {
return fmt.Errorf("compliance %.1f%% is below threshold %.1f%%", compliance, threshold)
return &ComplianceError{Compliance: compliance, Threshold: threshold}
}

return nil
Expand Down
21 changes: 21 additions & 0 deletions cmd/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package cmd

import "fmt"

// ComplianceError is returned when analysis completes successfully but the
// measured compliance score falls below the required threshold.
//
// It is distinct from a generic runtime error so that callers (e.g. Execute)
// can map it to a dedicated exit code:
//
// 0 – analysis passed (compliance ≥ threshold)
// 1 – compliance failure (compliance < threshold)
// 2 – runtime / configuration error
type ComplianceError struct {
Compliance float64
Threshold float64
}

func (e *ComplianceError) Error() string {
return fmt.Sprintf("compliance %.1f%% is below threshold %.1f%%", e.Compliance, e.Threshold)
}
7 changes: 6 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"errors"
"fmt"
"os"
"time"
Expand Down Expand Up @@ -48,7 +49,11 @@ func Execute() {
}

if err != nil {
os.Exit(1)
var complianceErr *ComplianceError
if errors.As(err, &complianceErr) {
os.Exit(1)
}
os.Exit(2)
}
}

Expand Down
Loading