Skip to content

Commit fbb9356

Browse files
committed
fix exit codes
Signed-off-by: Sylwester Piskozub <sylwesterpiskozub@gmail.com>
1 parent ce7a03a commit fbb9356

2 files changed

Lines changed: 7 additions & 8 deletions

File tree

app/cli/cmd/policy_develop_lint.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,18 @@ func newPolicyDevelopLintCmd() *cobra.Command {
4949
RegalConfig: regalConfig,
5050
})
5151
if err != nil {
52-
fmt.Errorf("linting failed: %w", err)
53-
os.Exit(1)
54-
return nil
52+
return fmt.Errorf("linting policy: %w", err)
5553
}
5654

5755
if result.Valid {
5856
logger.Info().Msg("policy is valid!")
5957
return nil
6058
}
6159

62-
encodeOutput(result, policyLintTable)
63-
os.Exit(1)
64-
return nil
60+
if err := encodeOutput(result, policyLintTable); err != nil {
61+
return fmt.Errorf("failed to encode output: %w", err)
62+
}
63+
return fmt.Errorf("%d issues found", len(result.Errors))
6564
},
6665
}
6766

@@ -75,7 +74,7 @@ func newPolicyDevelopLintCmd() *cobra.Command {
7574
func policyLintTable(result *action.PolicyLintResult) error {
7675
tw := table.NewWriter()
7776
tw.SetOutputMirror(os.Stdout)
78-
tw.AppendHeader(table.Row{"#", "Error"})
77+
tw.AppendHeader(table.Row{"#", "Issue"})
7978

8079
for i, err := range result.Errors {
8180
tw.AppendRow(table.Row{i + 1, err})

app/cli/internal/policydevel/lint.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ func (p *PolicyToLint) processRegalViolation(rawErr error, path string) {
369369

370370
// Replace "opa fmt" with "--format" in error messages
371371
errorStr = strings.ReplaceAll(errorStr, "`opa fmt`", "`--format`")
372-
//Regex matches file path, line number and error message like: /path/file:line: message
372+
// Regex matches file path, line number and error message like: /path/file:line: message
373373
re := regexp.MustCompile(`^(.*\.rego):(\d+):\s*(.+)$`)
374374

375375
// Handle the special case: "1 error occurred:"

0 commit comments

Comments
 (0)