-
Notifications
You must be signed in to change notification settings - Fork 233
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
Update diag convenience methods #449
Conversation
6ac2dfc
to
9309fb0
Compare
// No configuration | ||
if p.ConfigureFunc == nil && p.ConfigureContextFunc == nil { | ||
return diags | ||
return nil |
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 swapped some of these back, I think returning nil
when possible is more clear that its not a potential error case. Preserving the go idioms if possible is still useful. When someone does have warnings or are propagating from diag aware functions, the top level diags
and append
s make sense, but otherwise, I think it may be more effort and compromises on clarity.
// if err != nil { | ||
// return diag.FromErr(err) | ||
// } | ||
func FromErr(err error) Diagnostics { |
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.
Overall I do like this pattern, however I would still like a convenience to create a singular Diagnostic
from an error. Would it be crazy to keep the helpers for creating on a single diag, but then have a helper to quickly convert to the collection?
return diag.FromErr(err).ToDiags()
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.
It's valuable in scenarios where we have gathered warnings, and encounter a function that just returns a go error
if err != nil {
return append(diags, diag.FromErr(err))
}
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 the thing is, that you are burdening the 80% case for the 20% case, and you could easily rewrite that second one as:
if err != nil {
return append(diags, diag.FromErr(err)...)
}
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 wish the package was called diags
with this model, but that would collide with calling your slice diags
.
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
No description provided.