Skip to content

Commit

Permalink
fix: update ReferrerNotFound error to be more accurate
Browse files Browse the repository at this point in the history
  • Loading branch information
binbin-li committed Apr 18, 2024
1 parent cc7d780 commit 89586cb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
8 changes: 4 additions & 4 deletions errors/pluginerrors.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ var (
})

// ErrorCodeReferrersNotFound is returned if there is no ReferrerStore set.
ErrorCodeReferrersNotFound = Register("errcode", ErrorDescriptor{
Value: "REFERRERS_NOT_FOUND",
Message: "referrers not found",
Description: "No referrers are found. Please verify the subject has attached expected artifacts and refer to https://ratify.dev/docs/reference/store/ to investigate Referrer Store configuration.",
ErrorCodeEmptyVerifierReport = Register("errcode", ErrorDescriptor{
Value: "EMPTY_VERIFIER_REPORT",
Message: "empty verifier report",
Description: "No verifier report was generated. This might be due to various factors, such as a misconfiguration in the Referrer Store preventing access to the registry, lack of artifacts attached to the image, or the absence of appropriate verifiers corresponding to the referenced image artifacts.",
})

// Generic errors happen in plugins
Expand Down
19 changes: 19 additions & 0 deletions errors/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ type Error struct {
PluginName string `json:"pluginName,omitempty"`
LinkToDoc string `json:"linkToDoc,omitempty"`
Stack string `json:"stack,omitempty"`
Description string `json:"description,omitempty"`
}

// ErrorDescriptor provides relevant information about a given error code.
Expand Down Expand Up @@ -124,6 +125,11 @@ func (ec ErrorCode) Message() string {
return ec.Descriptor().Message
}

// Description returned the description of this error code.
func (ec ErrorCode) Description() string {
return ec.Descriptor().Description
}

// String returns the canonical identifier for this error code.
func (ec ErrorCode) String() string {
return ec.Descriptor().Value
Expand All @@ -149,6 +155,10 @@ func (ec ErrorCode) WithLinkToDoc(link string) Error {
return newError(ec, ec.Message()).WithLinkToDoc(link)
}

func (ec ErrorCode) WithDescription() Error {
return newError(ec, ec.Message()).WithDescription()
}

// WithPluginName returns a new Error object with pluginName set.
func (ec ErrorCode) WithPluginName(pluginName string) Error {
return newError(ec, ec.Message()).WithPluginName(pluginName)
Expand Down Expand Up @@ -223,6 +233,10 @@ func (e Error) Error() string {
errStr += fmt.Sprintf(", Detail: %v", e.Detail)
}

if e.Description != "" {
errStr += fmt.Sprintf(", Description: %v", e.Description)
}

if e.Stack != "" {
errStr += fmt.Sprintf(", Stack trace: %s", e.Stack)
}
Expand Down Expand Up @@ -261,6 +275,11 @@ func (e Error) WithLinkToDoc(link string) Error {
return e
}

func (e Error) WithDescription() Error {
e.Description = e.Code.Description()
return e
}

// IsEmpty returns true if the error is empty.
func (e Error) IsEmpty() bool {
return e == emptyError
Expand Down
2 changes: 1 addition & 1 deletion pkg/executor/core/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (executor Executor) verifySubjectInternal(ctx context.Context, verifyParame
}
if executor.PolicyEnforcer.GetPolicyType(ctx) == pt.ConfigPolicy {
if len(verifierReports) == 0 {
return types.VerifyResult{}, errors.ErrorCodeReferrersNotFound.WithComponentType(errors.Executor)
return types.VerifyResult{}, errors.ErrorCodeEmptyVerifierReport.WithComponentType(errors.Executor).WithDescription()
}
}
// If it requires embedded Rego Policy Engine make the decision, execute
Expand Down

0 comments on commit 89586cb

Please sign in to comment.