plans: Update error message for apply validation (#21312)
* 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.
This commit is contained in:
parent
6c3ad8eaad
commit
2dd64a7816
|
@ -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 {
|
func assertObjectCompatible(schema *configschema.Block, planned, actual cty.Value, path cty.Path) []error {
|
||||||
var errs []error
|
var errs []error
|
||||||
|
var atRoot string
|
||||||
|
if len(path) == 0 {
|
||||||
|
atRoot = "Root resource "
|
||||||
|
}
|
||||||
|
|
||||||
if planned.IsNull() && !actual.IsNull() {
|
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
|
return errs
|
||||||
}
|
}
|
||||||
if actual.IsNull() && !planned.IsNull() {
|
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
|
return errs
|
||||||
}
|
}
|
||||||
if planned.IsNull() {
|
if planned.IsNull() {
|
||||||
|
|
|
@ -245,7 +245,7 @@ func (n *EvalApply) Eval(ctx EvalContext) (interface{}, error) {
|
||||||
tfdiags.Error,
|
tfdiags.Error,
|
||||||
"Provider produced inconsistent result after apply",
|
"Provider produced inconsistent result after apply",
|
||||||
fmt.Sprintf(
|
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),
|
absAddr, n.ProviderAddr.Provider.String(), tfdiags.FormatError(err),
|
||||||
),
|
),
|
||||||
))
|
))
|
||||||
|
|
Loading…
Reference in New Issue