Skip to content

Commit

Permalink
plans: Update error message for apply validation (#21312)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
chrisst authored Jun 5, 2020
1 parent 6c3ad8e commit 2dd64a7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions plans/objchange/compatible.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
atRoot = "Root resource "
}

if planned.IsNull() && !actual.IsNull() {
errs = append(errs, path.NewErrorf("was absent, but now present"))
errs = append(errs, path.NewErrorf(fmt.Sprintf("%swas absent, but now present", atRoot)))
return errs
}
if actual.IsNull() && !planned.IsNull() {
errs = append(errs, path.NewErrorf("was present, but now absent"))
errs = append(errs, path.NewErrorf(fmt.Sprintf("%swas present, but now absent", atRoot)))
return errs
}
if planned.IsNull() {
Expand Down
2 changes: 1 addition & 1 deletion terraform/eval_apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ func (n *EvalApply) Eval(ctx EvalContext) (interface{}, error) {
tfdiags.Error,
"Provider produced inconsistent result after apply",
fmt.Sprintf(
"When applying changes to %s, provider %q produced an unexpected new value for %s.\n\nThis is a bug in the provider, which should be reported in the provider's own issue tracker.",
"When applying changes to %s, provider %q produced an unexpected new value: %s.\n\nThis is a bug in the provider, which should be reported in the provider's own issue tracker.",
absAddr, n.ProviderAddr.Provider.String(), tfdiags.FormatError(err),
),
))
Expand Down

0 comments on commit 2dd64a7

Please sign in to comment.