Skip to content

Commit fdb3bc4

Browse files
committed
Resolve linting errors
1 parent 7940fa9 commit fdb3bc4

File tree

2 files changed

+65
-21
lines changed

2 files changed

+65
-21
lines changed

internal/fwserver/schema_propose_new_plan.go

Lines changed: 64 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
14
package fwserver
25

36
import (
@@ -71,13 +74,40 @@ func proposedNew(ctx context.Context, s fwschema.Schema, path *tftypes.Attribute
7174
}
7275

7376
for name, blockType := range s.GetBlocks() {
74-
attrVal, _ := prior.ApplyTerraform5AttributePathStep(tftypes.AttributeName(name))
75-
priorVal := attrVal.(tftypes.Value)
77+
attrVal, err := prior.ApplyTerraform5AttributePathStep(tftypes.AttributeName(name))
78+
if err != nil {
79+
fwPath, fwPathDiags := fromtftypes.AttributePath(ctx, path, s)
80+
diags.Append(fwPathDiags...)
81+
82+
diags.Append(diag.NewAttributeErrorDiagnostic(fwPath,
83+
"Invalid Prior State Attribute Path",
84+
"An unexpected error occurred while trying to retrieve a value from prior state. "+
85+
"This is an error in terraform-plugin-framework used by the provider. "+
86+
"Please report the following to the provider developers.\n\n"+
87+
fmt.Sprintf("Original Error: %s", err),
88+
))
89+
return tftypes.Value{}, diags
90+
}
91+
92+
priorVal := attrVal.(tftypes.Value) //nolint
93+
94+
attrVal, err = config.ApplyTerraform5AttributePathStep(tftypes.AttributeName(name))
95+
if err != nil {
96+
fwPath, fwPathDiags := fromtftypes.AttributePath(ctx, path, s)
97+
diags.Append(fwPathDiags...)
7698

77-
attrVal, _ = config.ApplyTerraform5AttributePathStep(tftypes.AttributeName(name))
78-
configVal := attrVal.(tftypes.Value)
99+
diags.Append(diag.NewAttributeErrorDiagnostic(fwPath,
100+
"Invalid Config Attribute Path",
101+
"An unexpected error occurred while trying to retrieve a value from config. "+
102+
"This is an error in terraform-plugin-framework used by the provider. "+
103+
"Please report the following to the provider developers.\n\n"+
104+
fmt.Sprintf("Original Error: %s", err),
105+
))
106+
return tftypes.Value{}, diags
107+
}
108+
configVal := attrVal.(tftypes.Value) //nolint
79109

80-
nestedBlockDiags := diag.Diagnostics{}
110+
nestedBlockDiags := diag.Diagnostics{} //nolint
81111
newAttrs[name], nestedBlockDiags = proposeNewNestedBlock(ctx, s, blockType, path.WithAttributeName(name), priorVal, configVal)
82112
diags.Append(nestedBlockDiags...)
83113
if diags.HasError() {
@@ -242,7 +272,7 @@ func proposedNewAttributes(ctx context.Context, s fwschema.Schema, attrs map[str
242272
newVal = configVal
243273
}
244274
} else if nestedAttr, isNested := attr.(fwschema.NestedAttribute); isNested {
245-
nestedAttrDiags := diag.Diagnostics{}
275+
nestedAttrDiags := diag.Diagnostics{} //nolint
246276

247277
newVal, nestedAttrDiags = proposeNewNestedAttribute(ctx, s, nestedAttr, attrPath, priorVal, configVal)
248278
diags.Append(nestedAttrDiags...)
@@ -274,28 +304,28 @@ func proposeNewNestedAttribute(ctx context.Context, s fwschema.Schema, attr fwsc
274304
if config.IsNull() {
275305
break
276306
}
277-
nestedDiags := diag.Diagnostics{}
307+
nestedDiags := diag.Diagnostics{} //nolint
278308
newVal, nestedDiags = proposedNewNestedObjectAttributes(ctx, s, attr, path, prior, config)
279309
diags.Append(nestedDiags...)
280310
if nestedDiags.HasError() {
281311
return tftypes.Value{}, diags
282312
}
283313
case fwschema.NestingModeList:
284-
nestedDiags := diag.Diagnostics{}
314+
nestedDiags := diag.Diagnostics{} //nolint
285315
newVal, nestedDiags = proposedNewListNested(ctx, s, attr, path, prior, config)
286316
diags.Append(nestedDiags...)
287317
if nestedDiags.HasError() {
288318
return tftypes.Value{}, diags
289319
}
290320
case fwschema.NestingModeMap:
291-
nestedDiags := diag.Diagnostics{}
321+
nestedDiags := diag.Diagnostics{} //nolint
292322
newVal, nestedDiags = proposedNewMapNested(ctx, s, attr, path, prior, config)
293323
diags.Append(nestedDiags...)
294324
if nestedDiags.HasError() {
295325
return tftypes.Value{}, diags
296326
}
297327
case fwschema.NestingModeSet:
298-
nestedDiags := diag.Diagnostics{}
328+
nestedDiags := diag.Diagnostics{} //nolint
299329
newVal, nestedDiags = proposedNewSetNested(ctx, s, attr, path, prior, config)
300330
diags.Append(nestedDiags...)
301331
if nestedDiags.HasError() {
@@ -406,7 +436,7 @@ func proposedNewMapNested(ctx context.Context, s fwschema.Schema, attr fwschema.
406436
}
407437
}
408438

409-
nestedDiags := diag.Diagnostics{}
439+
nestedDiags := diag.Diagnostics{} //nolint
410440
newVals[name], nestedDiags = proposedNewNestedObjectAttributes(ctx, s, attr, path.WithElementKeyString(name), priorEV, configEV)
411441
diags.Append(nestedDiags...)
412442
if diags.HasError() {
@@ -685,21 +715,21 @@ func proposeNewNestedBlock(ctx context.Context, s fwschema.Schema, block fwschem
685715
if config.IsNull() {
686716
break
687717
}
688-
blockDiags := diag.Diagnostics{}
718+
blockDiags := diag.Diagnostics{} //nolint
689719
newVal, blockDiags = proposedNewNestedBlockObjectAttributes(ctx, s, block, path, prior, config)
690720
diags.Append(blockDiags...)
691721
if blockDiags.HasError() {
692722
return tftypes.Value{}, diags
693723
}
694724
case fwschema.BlockNestingModeList:
695-
blockDiags := diag.Diagnostics{}
725+
blockDiags := diag.Diagnostics{} //nolint
696726
newVal, blockDiags = proposedNewBlockListNested(ctx, s, block, path, prior, config)
697727
diags.Append(blockDiags...)
698728
if blockDiags.HasError() {
699729
return tftypes.Value{}, diags
700730
}
701731
case fwschema.BlockNestingModeSet:
702-
blockDiags := diag.Diagnostics{}
732+
blockDiags := diag.Diagnostics{} //nolint
703733
newVal, blockDiags = proposedNewBlockSetNested(ctx, s, block, path, prior, config)
704734
diags.Append(blockDiags...)
705735
if blockDiags.HasError() {
@@ -748,12 +778,25 @@ func proposedNewNestedBlockObjectAttributes(ctx context.Context, s fwschema.Sche
748778
))
749779
return tftypes.Value{}, diags
750780
}
751-
priorVal := attrVal.(tftypes.Value)
781+
priorVal := attrVal.(tftypes.Value) //nolint
752782

753-
attrVal, _ = config.ApplyTerraform5AttributePathStep(tftypes.AttributeName(name))
754-
configVal := attrVal.(tftypes.Value)
783+
attrVal, err = config.ApplyTerraform5AttributePathStep(tftypes.AttributeName(name))
784+
if err != nil {
785+
fwPath, fwPathDiags := fromtftypes.AttributePath(ctx, path, s)
786+
diags.Append(fwPathDiags...)
787+
788+
diags.Append(diag.NewAttributeErrorDiagnostic(fwPath,
789+
"Invalid Config Attribute Path",
790+
"An unexpected error occurred while trying to retrieve a value from config. "+
791+
"This is an error in terraform-plugin-framework used by the provider. "+
792+
"Please report the following to the provider developers.\n\n"+
793+
fmt.Sprintf("Original Error: %s", err),
794+
))
795+
return tftypes.Value{}, diags
796+
}
797+
configVal := attrVal.(tftypes.Value) //nolint
755798

756-
nestedBlockDiags := diag.Diagnostics{}
799+
nestedBlockDiags := diag.Diagnostics{} //nolint
757800
valuesMap[name], nestedBlockDiags = proposeNewNestedBlock(ctx, s, blockType, tftypes.NewAttributePath().WithAttributeName(name).WithElementKeyInt(0), priorVal, configVal)
758801
diags.Append(nestedBlockDiags...)
759802
if diags.HasError() {
@@ -1037,9 +1080,9 @@ func proposeNewNestedBlockObject(ctx context.Context, s fwschema.Schema, nestedB
10371080
}
10381081

10391082
attrVal, _ := config.ApplyTerraform5AttributePathStep(tftypes.AttributeName(name))
1040-
configVal := attrVal.(tftypes.Value)
1083+
configVal := attrVal.(tftypes.Value) //nolint
10411084

1042-
nestedBlockDiags := diag.Diagnostics{}
1085+
nestedBlockDiags := diag.Diagnostics{} //nolint
10431086
valuesMap[name], nestedBlockDiags = proposeNewNestedBlock(ctx, s, blockType, path.WithAttributeName(name), priorVal, configVal)
10441087
diags.Append(nestedBlockDiags...)
10451088
if nestedBlockDiags.HasError() {
@@ -1167,7 +1210,7 @@ func validPriorFromConfig(ctx context.Context, s fwschema.Schema, absPath *tftyp
11671210
valid = false
11681211
return false, stop
11691212
}
1170-
configV := configIface.(tftypes.Value)
1213+
configV := configIface.(tftypes.Value) //nolint
11711214

11721215
// we don't need to know the schema if both are equal
11731216
if configV.Equal(priorV) {

internal/fwserver/schema_propose_new_plan_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5754,6 +5754,7 @@ func TestSchemaProposeNewState(t *testing.T) {
57545754

57555755
for name, test := range tests {
57565756
t.Run(name, func(t *testing.T) {
5757+
t.Parallel()
57575758
priorStateVal := tftypes.NewValue(tftypes.DynamicPseudoType, nil)
57585759
if test.priorVal != nil {
57595760
schemaType := test.schema.Type().TerraformType(context.Background())

0 commit comments

Comments
 (0)