-
Notifications
You must be signed in to change notification settings - Fork 43
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
Handle diags from gRPC state upgrader #2053
Conversation
@@ -49,8 +49,8 @@ func upgradeResourceStateGRPC( | |||
RawState: &tfprotov5.RawState{JSON: jsonBytes}, | |||
Version: version, | |||
}) | |||
if err != nil { | |||
return cty.Value{}, nil, err | |||
if uerr := handleDiagnostics(ctx, resp.Diagnostics, err); uerr != 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.
This is the essential change. Do not ignore diagnostics, including errors, fail fast here.
pkg/tfshim/sdk-v2/provider2_test.go
Outdated
expectErr: func(t *testing.T, err error) { | ||
require.Error(t, err) | ||
autogold.Expect(`1 error occurred: | ||
* missing expected [ |
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.
The error message is not a great one.
It's losing attribute information from this String() method:
// ValidationError wraps validation errors reported by shims (currently shim v2 and tf5)
type ValidationError struct {
AttributePath cty.Path
Summary string
Detail string
}
func (e ValidationError) Error() string {
if e.Detail != "" {
return fmt.Sprintf("%s: %s", e.Summary, e.Detail)
}
return e.Summary
}
We could have had compute_resources.$.ec2_configuration
which is essential for debugging this.
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.
The actual message is also terrible because the internals of tfprotov5.UpgradeResourceState handler use a raw json parser and expect types to match; no more type checking. This works out because in TF the data that's passed in is already type-conformant. Any quick ideas to improve here .
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2053 +/- ##
==========================================
+ Coverage 61.37% 61.44% +0.07%
==========================================
Files 334 334
Lines 44947 44951 +4
==========================================
+ Hits 27585 27621 +36
+ Misses 15836 15805 -31
+ Partials 1526 1525 -1 ☔ View full report in Codecov by Sentry. |
Yeah I've seen the odd errors with the json parsing but I was under the impression that these only happen on type mismatches, which should be handled by the new type checking. Otherwise the changes here looks sensible. |
State parsing is not handled by type-checking and it's an odd place to put it since the user has more direct control of resource config than state. It's an interesting thought though perhaps we could. At least when mismatches of this sort happen it could provide better errors. Unfortunately the existing type-checking is not reusable at this level since it's written against pulumi types and values not TF-level types and values. |
I wonder if type-checking for the state values would be a good workaround for #1667 - it'd alert the user about a possible issue much sooner. Users can then act on that, do manual state edits, etc - still not a full fix but a better experience than what we have now. |
Maybe. IN theory with #1667 this situation should be guaranteed not to arise with new code but in practice it might. I wonder if this is tantamount to just not recovering cty.Value failures with approximate methods, the strict methods will type check and fail fast with some information |
I think maybe let's check this in, I'll follow up with some quick double-check to figure out if the error message can be better here. |
I think the current strategy is to install a panic handler if we get any type errors - so we still allow a recovery but if we panic during the recovery we catch it and print the helpful error. |
Yeah no, the error currently printed is anything but helpful. |
Isolating this from an AWS test failure; handling diags turns a panic into a regular error. Looks like the error message is still unfortunate. The test is isolated from pulumi/pulumi-aws#4015