Skip to content

Commit ccdf770

Browse files
committed
custom error
Signed-off-by: Jose I. Paris <jiparis@chainloop.dev>
1 parent be4e1ea commit ccdf770

7 files changed

Lines changed: 23 additions & 6 deletions

File tree

app/cli/cmd/attestation_push.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func newAttestationPushCmd() *cobra.Command {
130130
logger.Warn().Msg(exceptionBypassPolicyCheck)
131131
continue
132132
}
133-
return fmt.Errorf("your contract requires the policy %q to pass before continuing", eval.Name)
133+
return NewGateError(eval.Name)
134134
}
135135
}
136136
}
@@ -170,3 +170,15 @@ var (
170170
ErrBlockedByPolicyViolation = fmt.Errorf("the operator requires all policies to pass before continuing, please fix them and try again or temporarily bypass the policy check using --%s", exceptionFlagName)
171171
exceptionBypassPolicyCheck = fmt.Sprintf("Attention: You have opted to bypass the policy enforcement check and an operator has been notified of this exception.\nPlease make sure you are back on track with the policy evaluations and remove the --%s as soon as possible.", exceptionFlagName)
172172
)
173+
174+
type GateError struct {
175+
PolicyName string
176+
}
177+
178+
func NewGateError(policyName string) error {
179+
return &GateError{PolicyName: policyName}
180+
}
181+
182+
func (e *GateError) Error() string {
183+
return fmt.Sprintf("the policy %q is configured as a gate and has violations", e.PolicyName)
184+
}

app/cli/main.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ func errorInfo(err error, logger zerolog.Logger) (string, int) {
7878
}
7979
}
8080

81+
var gateErr *cmd.GateError
82+
8183
// Make overrides
8284
switch {
8385
case v1.IsCasBackendErrorReasonRequired(err):
@@ -101,6 +103,9 @@ func errorInfo(err error, logger zerolog.Logger) (string, int) {
101103
case errors.Is(err, cmd.ErrBlockedByPolicyViolation):
102104
// default exit code for policy violations
103105
exitCode = 3
106+
case errors.As(err, &gateErr):
107+
// exit code for gate errors
108+
exitCode = 4
104109
}
105110

106111
return msg, exitCode

app/controlplane/api/gen/frontend/workflowcontract/v1/crafting_schema.ts

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/controlplane/api/gen/jsonschema/workflowcontract.v1.PolicyAttachment.jsonschema.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/controlplane/api/gen/jsonschema/workflowcontract.v1.PolicyAttachment.schema.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/controlplane/api/workflowcontract/v1/crafting_schema.pb.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/controlplane/api/workflowcontract/v1/crafting_schema.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ message PolicyAttachment {
229229
}
230230
}];
231231

232-
// If true, the policy will act as a gate, failing the attestation if the policy fails
232+
// If true, the policy will act as a gate, returning an error code if the policy fails
233233
bool gate = 7;
234234

235235
message MaterialSelector {

0 commit comments

Comments
 (0)