Skip to content

Commit 719d14d

Browse files
committed
add validity checks and warn of deprecations for ValidateDiagFunc
1 parent 1365c81 commit 719d14d

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

helper/schema/schema.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -850,12 +850,16 @@ func (m schemaMap) internalValidate(topSchemaMap schemaMap, attrsOnly bool) erro
850850
return fmt.Errorf("%s: ValidateFunc is for validating user input, "+
851851
"there's nothing to validate on computed-only field", k)
852852
}
853+
if v.ValidateDiagFunc != nil {
854+
return fmt.Errorf("%s: ValidateDiagFunc is for validating user input, "+
855+
"there's nothing to validate on computed-only field", k)
856+
}
853857
}
854858

855-
if v.ValidateFunc != nil {
859+
if v.ValidateFunc != nil || v.ValidateDiagFunc != nil {
856860
switch v.Type {
857861
case TypeList, TypeSet:
858-
return fmt.Errorf("%s: ValidateFunc is not yet supported on lists or sets.", k)
862+
return fmt.Errorf("%s: ValidateFunc and ValidateDiagFunc are not yet supported on lists or sets.", k)
859863
}
860864
}
861865

@@ -868,6 +872,12 @@ func (m schemaMap) internalValidate(topSchemaMap schemaMap, attrsOnly bool) erro
868872
return fmt.Errorf("%s: Field name may only contain lowercase alphanumeric characters & underscores.", k)
869873
}
870874
}
875+
876+
// Warn of deprecations
877+
if v.ValidateFunc != nil && v.ValidateDiagFunc == nil {
878+
log.Printf("[WARN] ValidateFunc is deprecated, please use ValidateDiagFunc")
879+
}
880+
871881
}
872882

873883
return nil

0 commit comments

Comments
 (0)