-
Notifications
You must be signed in to change notification settings - Fork 97
tfsdk: Update Config, Plan, and State type GetAttribute methods to use reflection #167
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
Conversation
for idx, valueAsDiag := range valueAsDiags { | ||
if valueAsDiag.Severity() == diag.SeverityError { | ||
valueAsDiags[idx] = diag.NewAttributeErrorDiagnostic( | ||
path, | ||
valueAsDiag.Summary(), | ||
valueAsDiag.Detail(), | ||
) | ||
} else if valueAsDiag.Severity() == diag.SeverityWarning { | ||
valueAsDiags[idx] = diag.NewAttributeWarningDiagnostic( | ||
path, | ||
valueAsDiag.Summary(), | ||
valueAsDiag.Detail(), | ||
) | ||
} |
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.
Eek. Can we add an issue at least to have diag.Diagnostic
have a SetPath
method to avoid this kind of stuff?
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 created #169, but it might require some refactoring to the diag
package.
tfsdk/config.go
Outdated
func (c Config) GetAttribute(ctx context.Context, path *tftypes.AttributePath, target interface{}) diag.Diagnostics { | ||
attrValue, diags := c.getAttributeValue(ctx, path) | ||
|
||
if attrValue == nil || diags.HasError() { |
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'm still 🤔 about the case where attrValue
is nil
. If error diagnostics are returned, the provider will think that target
has been set, when it has not. If error diagnostics are returned, then the check is unnecessary. The only case in which the check helps us avoids a panic but is really hard to debug.
Do we want to catch a nil
attrValue
and return an error diagnostic for it, instead?
This may require some light rebase work depending on #185 |
…e reflection Reference: #134
…O for diagnostic SetPath
f8cc3a2
to
862229f
Compare
Rebased after #185 |
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.
Let's do it.
I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions. |
Closes #134