hashicorp / hashicorp/terraform-plugin-framework

types/basetypes: Panic with Collection Value Type Missing ElemType

Open
#779 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Go
Stars
384
Forks
107
Avg merge
3m
Merged PRs (30d)
1

Description

### Module version

```
v1.3.1
```

### Relevant provider source code

When implementing a default value, but not setting `defaults.{TYPE}Response.PlanValue` or diagnostics.

```go
func (d defaultImpl) ListDefault(ctx context.Context, req defaults.ListRequest, resp *defaults.ListResponse) {
// intentionally not setting resp.PlanValue before returning
}
```

The easier test case is directly creating an invalid value:

```go
basetypes.ListValue{}.ToTerraformValue(ctx)
```

### Terraform Configuration Files

N/A

### Debug Output

N/A

### Expected Behavior

In the case of the default value handling, the response should be automatically populated with a valid null value by default. For other usages of invalid value types, some form of fallback "missing type" behavior over a panic, similar to #755.

### Actual Behavior

```
--- FAIL: TestDataDefault (0.01s)
--- FAIL: TestDataDefault/list-attribute-request-path (0.00s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x30 pc=0x100a161ec]

goroutine 14 [running]:
testing.tRunner.func1.2({0x1010fe140, 0x10137c890})
/opt/homebrew/Cellar/go/1.20.5/libexec/src/testing/testing.go:1526 +0x1c8
testing.tRunner.func1()
/opt/homebrew/Cellar/go/1.20.5/libexec/src/testing/testing.go:1529 +0x384
panic({0x1010fe140, 0x10137c890})
/opt/homebrew/Cellar/go/1.20.5/libexec/src/runtime/panic.go:884 +0x204
github.com/hashicorp/terraform-plugin-framework/types/basetypes.ListValue.ToTerraformValue({{0x0, 0x0, 0x0}, {0x0, 0x0}, 0x0}, {0x101154860, 0x1400009c018})
/Users/bflad/src/github.com/hashicorp/terraform-plugin-framework/types/basetypes/list_value.go:208 +0x5c
```

### Steps to Reproduce

`go test`

### References

None

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.