From d54b52fa01983321f3a196046ae7ec343d32827b Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Tue, 28 Aug 2018 17:28:21 -0700 Subject: [PATCH] core: Fix error reporting for malformed provider response values --- terraform/eval_apply.go | 6 +++--- terraform/eval_diff.go | 6 +++--- terraform/eval_state.go | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/terraform/eval_apply.go b/terraform/eval_apply.go index 0599d2940..02cff0d5c 100644 --- a/terraform/eval_apply.go +++ b/terraform/eval_apply.go @@ -76,13 +76,13 @@ func (n *EvalApply) Eval(ctx EvalContext) (interface{}, error) { // incomplete. newVal := resp.NewState - for _, err := range schema.ImpliedType().TestConformance(newVal.Type()) { + for _, err := range newVal.Type().TestConformance(schema.ImpliedType()) { diags = diags.Append(tfdiags.Sourceless( tfdiags.Error, "Provider produced invalid object", fmt.Sprintf( - "Provider %q planned an invalid value for %s%s after apply, and so the result could not be saved.\n\nThis is a bug in the provider, which should be reported in the provider's own issue tracker.", - n.ProviderAddr.ProviderConfig.Type, absAddr, tfdiags.FormatError(err), + "Provider %q planned an invalid value after apply for %s. The result could not be saved.\n\nThis is a bug in the provider, which should be reported in the provider's own issue tracker.", + n.ProviderAddr.ProviderConfig.Type, tfdiags.FormatErrorPrefixed(err, absAddr.String()), ), )) } diff --git a/terraform/eval_diff.go b/terraform/eval_diff.go index 89bb97e7e..fdec6e30a 100644 --- a/terraform/eval_diff.go +++ b/terraform/eval_diff.go @@ -153,13 +153,13 @@ func (n *EvalDiff) Eval(ctx EvalContext) (interface{}, error) { // here, since that allows the provider to do special logic like a // DiffSuppressFunc, but we still require that the provider produces // a value whose type conforms to the schema. - for _, err := range schema.ImpliedType().TestConformance(plannedNewVal.Type()) { + for _, err := range plannedNewVal.Type().TestConformance(schema.ImpliedType()) { diags = diags.Append(tfdiags.Sourceless( tfdiags.Error, "Provider produced invalid plan", fmt.Sprintf( - "Provider %q planned an invalid value for %s%s.\n\nThis is a bug in the provider, which should be reported in the provider's own issue tracker.", - n.ProviderAddr.ProviderConfig.Type, absAddr, tfdiags.FormatError(err), + "Provider %q planned an invalid value for %s.\n\nThis is a bug in the provider, which should be reported in the provider's own issue tracker.", + n.ProviderAddr.ProviderConfig.Type, tfdiags.FormatErrorPrefixed(err, absAddr.String()), ), )) } diff --git a/terraform/eval_state.go b/terraform/eval_state.go index 6069c2e79..79adc5002 100644 --- a/terraform/eval_state.go +++ b/terraform/eval_state.go @@ -50,7 +50,7 @@ func (n *EvalReadState) Eval(ctx EvalContext) (interface{}, error) { } */ - schema := (*n.ProviderSchema).ResourceTypes[absAddr.Resource.Resource.Type] + schema := (*n.ProviderSchema).SchemaForResourceAddr(n.Addr.ContainingResource()) obj, err := src.Decode(schema.ImpliedType()) if err != nil { return nil, err @@ -103,7 +103,7 @@ func (n *EvalReadStateDeposed) Eval(ctx EvalContext) (interface{}, error) { } */ - schema := (*n.ProviderSchema).ResourceTypes[absAddr.Resource.Resource.Type] + schema := (*n.ProviderSchema).SchemaForResourceAddr(n.Addr.ContainingResource()) obj, err := src.Decode(schema.ImpliedType()) if err != nil { return nil, err