core: Fix error reporting for malformed provider response values

This commit is contained in:
Martin Atkins 2018-08-28 17:28:21 -07:00
parent 630b0d147d
commit d54b52fa01
3 changed files with 8 additions and 8 deletions

View File

@ -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()),
),
))
}

View File

@ -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()),
),
))
}

View File

@ -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