Skip to content

Commit 9321fe1

Browse files
apparentlymartpaddycarver
authored andcommitted
helper/schema: Adjusted validation error messages
Some of the validation error messages were written with the provider developer audience rather than the end-user audience in mind, and so in helping various folks in the community forum, etc I've occasionally seen folks be confused as to what these messages mean and what to do about them. Since I was here anyway I also did some general review of the terminology used and adjusted some things that were not necessarily confusing but that were using different terminology than Terraform Core would use for a similar problem. However, for many of them I didn't change them heavily because in many cases these validation errors are masked by equivalent schema-based validation in Terraform Core itself anyway, and so these can often be seen only by Terraform v0.10/v0.11 users.
1 parent e512e37 commit 9321fe1

File tree

2 files changed

+32
-32
lines changed

2 files changed

+32
-32
lines changed

helper/schema/schema.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,7 +1439,7 @@ func (m schemaMap) validate(
14391439
if err != nil {
14401440
return append(diags, diag.Diagnostic{
14411441
Severity: diag.Error,
1442-
Summary: "Loading Default",
1442+
Summary: "Failed to determine default value",
14431443
Detail: err.Error(),
14441444
AttributePath: path,
14451445
})
@@ -1453,7 +1453,7 @@ func (m schemaMap) validate(
14531453
if err != nil {
14541454
return append(diags, diag.Diagnostic{
14551455
Severity: diag.Error,
1456-
Summary: "ExactlyOne",
1456+
Summary: "Invalid combination of arguments",
14571457
Detail: err.Error(),
14581458
AttributePath: path,
14591459
})
@@ -1463,7 +1463,7 @@ func (m schemaMap) validate(
14631463
if err != nil {
14641464
return append(diags, diag.Diagnostic{
14651465
Severity: diag.Error,
1466-
Summary: "AtLeastOne",
1466+
Summary: "Missing required argument",
14671467
Detail: err.Error(),
14681468
AttributePath: path,
14691469
})
@@ -1485,8 +1485,8 @@ func (m schemaMap) validate(
14851485
// This is a computed-only field
14861486
return append(diags, diag.Diagnostic{
14871487
Severity: diag.Error,
1488-
Summary: "Computed attributes cannot be set",
1489-
Detail: fmt.Sprintf("Computed attributes cannot be set, but a value was set for %q.", k),
1488+
Summary: "Value for unconfigurable attribute",
1489+
Detail: fmt.Sprintf("Can't configure a value for %q: its value will be decided automatically based on the result of applying this configuration.", k),
14901490
AttributePath: path,
14911491
})
14921492
}
@@ -1495,7 +1495,7 @@ func (m schemaMap) validate(
14951495
if err != nil {
14961496
return append(diags, diag.Diagnostic{
14971497
Severity: diag.Error,
1498-
Summary: "RequiredWith",
1498+
Summary: "Missing required argument",
14991499
Detail: err.Error(),
15001500
AttributePath: path,
15011501
})
@@ -1510,7 +1510,7 @@ func (m schemaMap) validate(
15101510
if schema.Deprecated != "" {
15111511
return append(diags, diag.Diagnostic{
15121512
Severity: diag.Warning,
1513-
Summary: "Attribute is deprecated",
1513+
Summary: "Argument is deprecated",
15141514
Detail: schema.Deprecated,
15151515
AttributePath: path,
15161516
})
@@ -1522,7 +1522,7 @@ func (m schemaMap) validate(
15221522
if err != nil {
15231523
return append(diags, diag.Diagnostic{
15241524
Severity: diag.Error,
1525-
Summary: "ConflictsWith",
1525+
Summary: "Conflicting configuration arguments",
15261526
Detail: err.Error(),
15271527
AttributePath: path,
15281528
})
@@ -1699,7 +1699,7 @@ func (m schemaMap) validateList(
16991699
if rawV.Kind() != reflect.Slice {
17001700
return append(diags, diag.Diagnostic{
17011701
Severity: diag.Error,
1702-
Summary: "Attribute should be a list",
1702+
Summary: "Attribute must be a list",
17031703
AttributePath: path,
17041704
})
17051705
}
@@ -1717,17 +1717,17 @@ func (m schemaMap) validateList(
17171717
if schema.MaxItems > 0 && rawV.Len() > schema.MaxItems {
17181718
return append(diags, diag.Diagnostic{
17191719
Severity: diag.Error,
1720-
Summary: "List longer than MaxItems",
1721-
Detail: fmt.Sprintf("Attribute supports %d item maximum, config has %d declared", schema.MaxItems, rawV.Len()),
1720+
Summary: "Too many list items",
1721+
Detail: fmt.Sprintf("Attribute supports %d item maximum, but config has %d declared.", schema.MaxItems, rawV.Len()),
17221722
AttributePath: path,
17231723
})
17241724
}
17251725

17261726
if schema.MinItems > 0 && rawV.Len() < schema.MinItems {
17271727
return append(diags, diag.Diagnostic{
17281728
Severity: diag.Error,
1729-
Summary: "List shorter than MinItems",
1730-
Detail: fmt.Sprintf("Attribute supports %d item minimum, config has %d declared", schema.MinItems, rawV.Len()),
1729+
Summary: "Not enough list items",
1730+
Detail: fmt.Sprintf("Attribute requires %d item minimum, but config has only %d declared.", schema.MinItems, rawV.Len()),
17311731
AttributePath: path,
17321732
})
17331733
}
@@ -1794,7 +1794,7 @@ func (m schemaMap) validateMap(
17941794
if reifiedOk && raw == reified && !c.IsComputed(k) {
17951795
return append(diags, diag.Diagnostic{
17961796
Severity: diag.Error,
1797-
Summary: "Attribute should be a map",
1797+
Summary: "Attribute must be a map",
17981798
AttributePath: path,
17991799
})
18001800
}
@@ -1805,7 +1805,7 @@ func (m schemaMap) validateMap(
18051805
default:
18061806
return append(diags, diag.Diagnostic{
18071807
Severity: diag.Error,
1808-
Summary: "Attribute should be a map",
1808+
Summary: "Attribute must be a map",
18091809
AttributePath: path,
18101810
})
18111811
}
@@ -1832,7 +1832,7 @@ func (m schemaMap) validateMap(
18321832
if v.Kind() != reflect.Map {
18331833
return append(diags, diag.Diagnostic{
18341834
Severity: diag.Error,
1835-
Summary: "Attribute should be a map",
1835+
Summary: "Attribute must be a map",
18361836
AttributePath: path,
18371837
})
18381838
}
@@ -2111,7 +2111,7 @@ func (m schemaMap) validateType(
21112111
if schema.Deprecated != "" {
21122112
diags = append(diags, diag.Diagnostic{
21132113
Severity: diag.Warning,
2114-
Summary: "Deprecated Attribute",
2114+
Summary: "Argument is deprecated",
21152115
Detail: schema.Deprecated,
21162116
AttributePath: path,
21172117
})

helper/schema/schema_test.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5506,7 +5506,7 @@ func TestSchemaMap_Validate(t *testing.T) {
55065506

55075507
Err: true,
55085508
Errors: []error{
5509-
fmt.Errorf("Error: Attribute should be a list"),
5509+
fmt.Errorf("Error: Attribute must be a list"),
55105510
},
55115511
},
55125512

@@ -5527,7 +5527,7 @@ func TestSchemaMap_Validate(t *testing.T) {
55275527

55285528
Err: true,
55295529
Errors: []error{
5530-
fmt.Errorf("Error: Attribute should be a list"),
5530+
fmt.Errorf("Error: Attribute must be a list"),
55315531
},
55325532
},
55335533

@@ -5563,7 +5563,7 @@ func TestSchemaMap_Validate(t *testing.T) {
55635563
},
55645564

55655565
Warnings: []string{
5566-
"Warning: Attribute is deprecated: please use 'new_news' instead",
5566+
"Warning: Argument is deprecated: please use 'new_news' instead",
55675567
},
55685568
},
55695569

@@ -5953,7 +5953,7 @@ func TestSchemaMap_Validate(t *testing.T) {
59535953
Err: false,
59545954

59555955
Warnings: []string{
5956-
"Warning: Deprecated Attribute: please use 'new_news' instead",
5956+
"Warning: Argument is deprecated: please use 'new_news' instead",
59575957
},
59585958
},
59595959

@@ -5991,7 +5991,7 @@ func TestSchemaMap_Validate(t *testing.T) {
59915991

59925992
Err: true,
59935993
Errors: []error{
5994-
fmt.Errorf(`Error: ConflictsWith: "blacklist": conflicts with whitelist`),
5994+
fmt.Errorf(`Error: Conflicting configuration arguments: "blacklist": conflicts with whitelist`),
59955995
},
59965996
},
59975997

@@ -6087,8 +6087,8 @@ func TestSchemaMap_Validate(t *testing.T) {
60876087

60886088
Err: true,
60896089
Errors: []error{
6090-
fmt.Errorf(`Error: ConflictsWith: "blacklist": conflicts with greenlist`),
6091-
fmt.Errorf(`Error: ConflictsWith: "greenlist": conflicts with blacklist`),
6090+
fmt.Errorf(`Error: Conflicting configuration arguments: "blacklist": conflicts with greenlist`),
6091+
fmt.Errorf(`Error: Conflicting configuration arguments: "greenlist": conflicts with blacklist`),
60926092
},
60936093
},
60946094

@@ -6132,7 +6132,7 @@ func TestSchemaMap_Validate(t *testing.T) {
61326132

61336133
Err: true,
61346134
Errors: []error{
6135-
fmt.Errorf(`Error: ConflictsWith: "optional_att": conflicts with required_att`),
6135+
fmt.Errorf(`Error: Conflicting configuration arguments: "optional_att": conflicts with required_att`),
61366136
},
61376137
},
61386138

@@ -6159,8 +6159,8 @@ func TestSchemaMap_Validate(t *testing.T) {
61596159

61606160
Err: true,
61616161
Errors: []error{
6162-
fmt.Errorf(`Error: ConflictsWith: "bar_att": conflicts with foo_att`),
6163-
fmt.Errorf(`Error: ConflictsWith: "foo_att": conflicts with bar_att`),
6162+
fmt.Errorf(`Error: Conflicting configuration arguments: "bar_att": conflicts with foo_att`),
6163+
fmt.Errorf(`Error: Conflicting configuration arguments: "foo_att": conflicts with bar_att`),
61646164
},
61656165
},
61666166

@@ -6528,7 +6528,7 @@ func TestSchemaMap_Validate(t *testing.T) {
65286528

65296529
ws := diagutils.WarningDiags(diags).Warnings()
65306530
if !reflect.DeepEqual(ws, tc.Warnings) {
6531-
t.Fatalf("%q: warnings:\n\nexpected: %#v\ngot:%#v", tn, tc.Warnings, ws)
6531+
t.Fatalf("%q: warnings:\n\ngot: %#v\nwant: %#v", tn, ws, tc.Warnings)
65326532
}
65336533

65346534
es := diagutils.ErrorDiags(diags).Errors()
@@ -6537,7 +6537,7 @@ func TestSchemaMap_Validate(t *testing.T) {
65376537
sort.Sort(errorSort(tc.Errors))
65386538

65396539
if !errorEquals(es, tc.Errors) {
6540-
t.Fatalf("%q: errors:\n\nexpected: %q\ngot: %q", tn, tc.Errors, es)
6540+
t.Fatalf("%q: errors:\n\ngot: %q\nwant: %q", tn, es, tc.Errors)
65416541
}
65426542
}
65436543
})
@@ -6583,7 +6583,7 @@ func TestSchemaSet_ValidateMaxItems(t *testing.T) {
65836583
Diff: nil,
65846584
Err: true,
65856585
Errors: []error{
6586-
fmt.Errorf("Error: List longer than MaxItems: Attribute supports 1 item maximum, config has 2 declared"),
6586+
fmt.Errorf("Error: Too many list items: Attribute supports 1 item maximum, but config has 2 declared."),
65876587
},
65886588
},
65896589
"#1": {
@@ -6705,7 +6705,7 @@ func TestSchemaSet_ValidateMinItems(t *testing.T) {
67056705
Diff: nil,
67066706
Err: true,
67076707
Errors: []error{
6708-
fmt.Errorf("Error: List shorter than MinItems: Attribute supports 2 item minimum, config has 1 declared"),
6708+
fmt.Errorf("Error: Not enough list items: Attribute requires 2 item minimum, but config has only 1 declared."),
67096709
},
67106710
},
67116711
}
@@ -6729,7 +6729,7 @@ func TestSchemaSet_ValidateMinItems(t *testing.T) {
67296729
es := diagutils.ErrorDiags(diags).Errors()
67306730
if tc.Errors != nil {
67316731
if !errorEquals(es, tc.Errors) {
6732-
t.Fatalf("%q: expected: %q\ngot: %q", tn, tc.Errors, es)
6732+
t.Fatalf("%q: wrong errors\ngot: %q\nwant: %q", tn, es, tc.Errors)
67336733
}
67346734
}
67356735
}

0 commit comments

Comments
 (0)