Skip to content
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 error message for apply validation #21312

Merged

Conversation

chrisst
Copy link
Contributor

@chrisst chrisst commented May 15, 2019

Add a hint that the validation failure has occurred at the root of the resource
schema to the error message. This is because the root resource has an empty
path when being validated and the path is being relied upon to provide context
into the error message.

In practice when the ID of a resource gets cleared accidentally due to a bug during Create the entire actual schema is null. The user facing error message when this happens is:

Error: Provider produced inconsistent result after apply

When applying changes to google_new_service.default, provider
“google-beta” produced an unexpected new value for was present, but now
absent.

This PR would change the message to:

Error: Provider produced inconsistent result after apply

When applying changes to google_new_service.default, provider
"google-beta" produced an unexpected new value: Root resource was present, but
now absent.

Add a hint that the validation failure has occurred at the root of the resource
schema to the error message. This is because the root resource has an empty
path when being validated and the path is being relied upon to provide context
into the error message.
@hashicorp-cla
Copy link

hashicorp-cla commented May 15, 2019

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@mildwonkey mildwonkey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @chrisst, thank you for submitting this !

It does not appear that your implementation is complete: what is the result if the path is not empty? It could be that I don't completely understand the situation that leads to this confusing output - is there a GitHub issue that describes the bug that lead you to open this PR? It's easier to review PRs when we have an open issue; it gives us a chance to understand the root cause and it can help to have reproduction cases so we can write tests.

If you are still interested in working on this PR (I know it's been awhile since you opened this and I am sorry for the long silence), let's continue this discussion about the problem space and design. It would help if you could point to any related GitHub issues.

@@ -28,12 +28,17 @@ func AssertObjectCompatible(schema *configschema.Block, planned, actual cty.Valu

func assertObjectCompatible(schema *configschema.Block, planned, actual cty.Value, path cty.Path) []error {
var errs []error
var atRoot string
if len(path) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if this is not 0? Is there a value we can use in those cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On line 54 of this PR, if path is not zero it's used to print out the path of the offending field. The issue was that if path was empty, eg it was a root field, the error message that got generated from "append(errs, path.NewErrorf("inconsistent values for sensitive attribute"))" generates a message that doesn't make sense - see the message in the PR description. So IIRC the only situation that wasn't already handled well was if the path was zero.

@chrisst
Copy link
Contributor Author

chrisst commented Jun 5, 2020

This PR was meant to assist provider developers in finding a bad configuration for a resource they are developing. There isn't an issue because it's hopefully an error situation that shouldn't make it to a shipped version of a resource. I just had to dig into code a bit to figure out what the real error was and thought I'd leave better bread crumbs for the next person.
It's been a year so I don't remember exactly how to repro but I think changing a resource's create method so clear the id but return without error will throw this.

@mildwonkey
Copy link
Contributor

Thank you very much for the explanation @chrisst , now I follow you.

If you'd like (as long as I have the ability to push to your fork), I can resolve the conflict for you, otherwise you can do it yourself and I will approve this PR - I'll leave that up to you but I'm happy to take over since you've waited so long already.

@chrisst
Copy link
Contributor Author

chrisst commented Jun 5, 2020

conflict resolved, thanks!

@codecov
Copy link

codecov bot commented Jun 5, 2020

Codecov Report

Merging #21312 into master will decrease coverage by 0.00%.
The diff coverage is 100.00%.

Impacted Files Coverage Δ
plans/objchange/compatible.go 68.66% <100.00%> (+0.43%) ⬆️
terraform/eval_apply.go 71.29% <100.00%> (ø)
dag/marshal.go 52.27% <0.00%> (-1.14%) ⬇️
backend/remote/backend_common.go 54.57% <0.00%> (-0.68%) ⬇️
terraform/evaluate.go 53.15% <0.00%> (-0.46%) ⬇️

Copy link
Contributor

@mildwonkey mildwonkey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! This commit will be in the next terraform release (should be 0.13-beta2)

@mildwonkey mildwonkey merged commit 2dd64a7 into hashicorp:master Jun 5, 2020
mildwonkey pushed a commit that referenced this pull request Jun 12, 2020
* Update error message for apply validation

Add a hint that the validation failure has occurred at the root of the resource
schema to the error message. This is because the root resource has an empty
path when being validated and the path is being relied upon to provide context
into the error message.
@ghost
Copy link

ghost commented Jul 6, 2020

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.

@ghost ghost locked and limited conversation to collaborators Jul 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants