-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make route domain error specific #15082
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #15082 +/- ##
==========================================
+ Coverage 84.11% 84.89% +0.77%
==========================================
Files 213 213
Lines 16783 13107 -3676
==========================================
- Hits 14117 11127 -2990
+ Misses 2315 1623 -692
- Partials 351 357 +6 ☔ View full report in Codecov by Sentry. |
@@ -119,12 +129,12 @@ func DomainNameFromTemplate(ctx context.Context, r metav1.ObjectMeta, name strin | |||
} | |||
|
|||
if err := templ.Execute(&buf, data); err != nil { | |||
return "", fmt.Errorf("error executing the DomainTemplate: %w", err) | |||
return "", DomainNameError{msg: fmt.Errorf("error executing the DomainTemplate: %w", err).Error()} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still need to use fmt.Errorf if we call .Error() on it anyway?
pkg/reconciler/route/route.go
Outdated
@@ -118,7 +118,11 @@ func (c *Reconciler) ReconcileKind(ctx context.Context, r *v1.Route) pkgreconcil | |||
traffic, err := c.configureTraffic(ctx, r) | |||
if traffic == nil || err != nil { | |||
if err != nil { | |||
r.Status.MarkUnknownTrafficError(err.Error()) | |||
if errors.As(err, &domains.DomainNameError{}) { | |||
r.Status.MarkRevisionTargetTrafficError("ErrorConfig", err.Error()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have constants for ErrorConfig
somewhere? Or why do we even need the reason as there is only one value here?
@dprotaso @izabelacg pls review. |
pkg/reconciler/route/route.go
Outdated
@@ -118,7 +120,11 @@ func (c *Reconciler) ReconcileKind(ctx context.Context, r *v1.Route) pkgreconcil | |||
traffic, err := c.configureTraffic(ctx, r) | |||
if traffic == nil || err != nil { | |||
if err != nil { | |||
r.Status.MarkUnknownTrafficError(err.Error()) | |||
if errors.As(err, &domains.DomainNameError{}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think errors.Is
is more apt since you're not using special fields in DomainNameError
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
error.Is will not work in this case (custom error) as it does not check the type. It returns false. In its code it has:
if isComparable && err == target {
return true
}
This will never be equal, unless we have a ref of some global error with a specific msg eg. created with errors.New().
errors.As does this check:
if reflectlite.TypeOf(err).AssignableTo(targetType) {
val.Elem().Set(reflectlite.ValueOf(err))
return true
}
that matches the error.
See also
https://stackoverflow.com/questions/39121172/how-to-compare-go-errors.
https://medium.com/@reetas/exploring-the-appropriate-use-cases-for-errors-is-and-errors-as-in-comparing-errors-in-golang-3584c6bc5417
Anyway I will use some predefined error to mark the tree, I can avoid the custom error if that is the goal (since it has no extra fields).
@dprotaso I changed the error stuff. Btw current error msg is:
Is this now ok to go in? |
I think what you had before was fine (having the struct) you just need to add your own |
That is just a type check at the end of the day, I was more in favor of reusing existing code but wfm. |
@dprotaso your suggestion also makes things a bit restrictive for future use as error typecheck (as it is already known), does not support wrapped errors: Could we avoid that and keep current implementaion? |
Sure |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: dprotaso, skonto The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Can you update the PR body with a release note? |
* make route domain error specific * fixes * fix quote * move to errors.Is * lint
* make route domain error specific * fixes * fix quote * move to errors.Is * lint
* make route domain error specific * fixes * fix quote * move to errors.Is * lint
Fixes #12149
Proposed Changes
Instead of:
we get:
Release Note
Reason and status for domain errors is no more specific to indicate a permanent issue.