Skip to content

Commit 11b5cbb

Browse files
extract: improve nil error
1 parent a315ea6 commit 11b5cbb

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

statecheck/extract_bool_value.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func (e extractBoolValue) CheckState(ctx context.Context, req CheckStateRequest,
6262
}
6363

6464
if result == nil {
65-
resp.Error = fmt.Errorf("attribute '%s' not found in '%s'", e.attributePath, e.resourceAddress)
65+
resp.Error = fmt.Errorf("nil: result for attribute '%s' in '%s'", e.attributePath, e.resourceAddress)
6666

6767
return
6868
}
@@ -72,6 +72,7 @@ func (e extractBoolValue) CheckState(ctx context.Context, req CheckStateRequest,
7272
*e.targetVar = t
7373
default:
7474
resp.Error = fmt.Errorf("invalid type for attribute '%s' in '%s'. Expected: bool, Got: %T", e.attributePath, e.resourceAddress, t)
75+
7576
return
7677
}
7778
}

statecheck/extract_bool_value_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import (
88
"regexp"
99
"testing"
1010

11+
"github.com/hashicorp/terraform-plugin-sdk/terraform"
1112
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1213

1314
r "github.com/hashicorp/terraform-plugin-testing/helper/resource"
1415
"github.com/hashicorp/terraform-plugin-testing/statecheck"
15-
"github.com/hashicorp/terraform-plugin-testing/terraform"
1616
"github.com/hashicorp/terraform-plugin-testing/tfjsonpath"
1717
)
1818

@@ -103,7 +103,7 @@ func TestExtractBoolValue_CheckState_Null(t *testing.T) {
103103
&targetVar,
104104
),
105105
},
106-
ExpectError: regexp.MustCompile(`invalid type for attribute \'float_attribute\' in \'test_resource\.one\'. Expected: bool, Got: json\.Number`),
106+
ExpectError: regexp.MustCompile(`nil: result for attribute \'bool_attribute\' in \'test_resource.one\'`),
107107
},
108108
},
109109
})

0 commit comments

Comments
 (0)