Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

types/basetypes: Prevent panics in ListType, MapType, and SetType methods when ElemType field is not set #755

Merged
merged 2 commits into from
Jun 12, 2023

Conversation

bflad
Copy link
Member

@bflad bflad commented Jun 9, 2023

Closes #714

Previously before logic updates:

--- FAIL: TestListTypeString (0.00s)
    --- FAIL: TestListTypeString/ElemType-missing (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=0x28 pc=0x102ff0068]

goroutine 19 [running]:
testing.tRunner.func1.2({0x1030efe00, 0x1032e7b10})
	/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({0x1030efe00, 0x1032e7b10})
	/opt/homebrew/Cellar/go/1.20.5/libexec/src/runtime/panic.go:884 +0x204
github.com/hashicorp/terraform-plugin-framework/types/basetypes.ListType.String(...)
	/Users/bflad/src/github.com/hashicorp/terraform-plugin-framework/types/basetypes/list_type.go:115
github.com/hashicorp/terraform-plugin-framework/types/basetypes.TestListTypeString.func1(0x14000082ea0)
	/Users/bflad/src/github.com/hashicorp/terraform-plugin-framework/types/basetypes/list_type_test.go:287 +0x48
testing.tRunner(0x14000082ea0, 0x1400009a6f0)
	/opt/homebrew/Cellar/go/1.20.5/libexec/src/testing/testing.go:1576 +0x10c
created by testing.(*T).Run
	/opt/homebrew/Cellar/go/1.20.5/libexec/src/testing/testing.go:1629 +0x368

--- FAIL: TestListTypeTerraformType (0.00s)
    --- FAIL: TestListTypeTerraformType/ElemType-missing (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=0x104acdd8c]

goroutine 38 [running]:
testing.tRunner.func1.2({0x104bd45a0, 0x104dcbb10})
	/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({0x104bd45a0, 0x104dcbb10})
	/opt/homebrew/Cellar/go/1.20.5/libexec/src/runtime/panic.go:884 +0x204
github.com/hashicorp/terraform-plugin-framework/types/basetypes.ListType.TerraformType(...)
	/Users/bflad/src/github.com/hashicorp/terraform-plugin-framework/types/basetypes/list_type.go:53
github.com/hashicorp/terraform-plugin-framework/types/basetypes.TestListTypeTerraformType.func1(0x14000103860)
	/Users/bflad/src/github.com/hashicorp/terraform-plugin-framework/types/basetypes/list_type_test.go:71 +0x5c
testing.tRunner(0x14000103860, 0x1400011c9f0)
	/opt/homebrew/Cellar/go/1.20.5/libexec/src/testing/testing.go:1576 +0x10c
created by testing.(*T).Run
	/opt/homebrew/Cellar/go/1.20.5/libexec/src/testing/testing.go:1629 +0x368

--- FAIL: TestListTypeValueFromTerraform (0.00s)
    --- FAIL: TestListTypeValueFromTerraform/missing-element-type (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=0x10515a414]

goroutine 28 [running]:
testing.tRunner.func1.2({0x1052785a0, 0x10546fb10})
	/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({0x1052785a0, 0x10546fb10})
	/opt/homebrew/Cellar/go/1.20.5/libexec/src/runtime/panic.go:884 +0x204
github.com/hashicorp/terraform-plugin-framework/types/basetypes.ListType.ValueFromTerraform({{0x0?, 0x0?}}, {0x1052c5630, 0x140000a4018}, {{0x1052c70d0?, 0x140000a35c0?}, {0x1052599c0?, 0x140000b62b8?}})
	/Users/bflad/src/github.com/hashicorp/terraform-plugin-framework/types/basetypes/list_type.go:61 +0x64
github.com/hashicorp/terraform-plugin-framework/types/basetypes.TestListTypeValueFromTerraform.func1(0x140001389c0)
	/Users/bflad/src/github.com/hashicorp/terraform-plugin-framework/types/basetypes/list_type_test.go:195 +0x60
testing.tRunner(0x140001389c0, 0x140000928a0)
	/opt/homebrew/Cellar/go/1.20.5/libexec/src/testing/testing.go:1576 +0x10c
created by testing.(*T).Run
	/opt/homebrew/Cellar/go/1.20.5/libexec/src/testing/testing.go:1629 +0x368

…e` methods when `ElemType` field is not set

Reference: #714

Previously before logic updates:

```
--- FAIL: TestListTypeString (0.00s)
    --- FAIL: TestListTypeString/ElemType-missing (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=0x28 pc=0x102ff0068]

goroutine 19 [running]:
testing.tRunner.func1.2({0x1030efe00, 0x1032e7b10})
	/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({0x1030efe00, 0x1032e7b10})
	/opt/homebrew/Cellar/go/1.20.5/libexec/src/runtime/panic.go:884 +0x204
github.com/hashicorp/terraform-plugin-framework/types/basetypes.ListType.String(...)
	/Users/bflad/src/github.com/hashicorp/terraform-plugin-framework/types/basetypes/list_type.go:115
github.com/hashicorp/terraform-plugin-framework/types/basetypes.TestListTypeString.func1(0x14000082ea0)
	/Users/bflad/src/github.com/hashicorp/terraform-plugin-framework/types/basetypes/list_type_test.go:287 +0x48
testing.tRunner(0x14000082ea0, 0x1400009a6f0)
	/opt/homebrew/Cellar/go/1.20.5/libexec/src/testing/testing.go:1576 +0x10c
created by testing.(*T).Run
	/opt/homebrew/Cellar/go/1.20.5/libexec/src/testing/testing.go:1629 +0x368

--- FAIL: TestListTypeTerraformType (0.00s)
    --- FAIL: TestListTypeTerraformType/ElemType-missing (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=0x104acdd8c]

goroutine 38 [running]:
testing.tRunner.func1.2({0x104bd45a0, 0x104dcbb10})
	/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({0x104bd45a0, 0x104dcbb10})
	/opt/homebrew/Cellar/go/1.20.5/libexec/src/runtime/panic.go:884 +0x204
github.com/hashicorp/terraform-plugin-framework/types/basetypes.ListType.TerraformType(...)
	/Users/bflad/src/github.com/hashicorp/terraform-plugin-framework/types/basetypes/list_type.go:53
github.com/hashicorp/terraform-plugin-framework/types/basetypes.TestListTypeTerraformType.func1(0x14000103860)
	/Users/bflad/src/github.com/hashicorp/terraform-plugin-framework/types/basetypes/list_type_test.go:71 +0x5c
testing.tRunner(0x14000103860, 0x1400011c9f0)
	/opt/homebrew/Cellar/go/1.20.5/libexec/src/testing/testing.go:1576 +0x10c
created by testing.(*T).Run
	/opt/homebrew/Cellar/go/1.20.5/libexec/src/testing/testing.go:1629 +0x368

--- FAIL: TestListTypeValueFromTerraform (0.00s)
    --- FAIL: TestListTypeValueFromTerraform/missing-element-type (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=0x10515a414]

goroutine 28 [running]:
testing.tRunner.func1.2({0x1052785a0, 0x10546fb10})
	/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({0x1052785a0, 0x10546fb10})
	/opt/homebrew/Cellar/go/1.20.5/libexec/src/runtime/panic.go:884 +0x204
github.com/hashicorp/terraform-plugin-framework/types/basetypes.ListType.ValueFromTerraform({{0x0?, 0x0?}}, {0x1052c5630, 0x140000a4018}, {{0x1052c70d0?, 0x140000a35c0?}, {0x1052599c0?, 0x140000b62b8?}})
	/Users/bflad/src/github.com/hashicorp/terraform-plugin-framework/types/basetypes/list_type.go:61 +0x64
github.com/hashicorp/terraform-plugin-framework/types/basetypes.TestListTypeValueFromTerraform.func1(0x140001389c0)
	/Users/bflad/src/github.com/hashicorp/terraform-plugin-framework/types/basetypes/list_type_test.go:195 +0x60
testing.tRunner(0x140001389c0, 0x140000928a0)
	/opt/homebrew/Cellar/go/1.20.5/libexec/src/testing/testing.go:1576 +0x10c
created by testing.(*T).Run
	/opt/homebrew/Cellar/go/1.20.5/libexec/src/testing/testing.go:1629 +0x368
```
@bflad bflad added the bug Something isn't working label Jun 9, 2023
@bflad bflad requested a review from a team as a code owner June 9, 2023 20:30
Copy link
Member

@austinvalle austinvalle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me. Good stuff! 🚀

Do we need an issue tracking the long-term/major version change to ElemType that is mentioned in #714 ?

@bflad
Copy link
Member Author

bflad commented Jun 12, 2023

@austinvalle created #761 👍

@bflad bflad merged commit 481f1bf into main Jun 12, 2023
19 checks passed
@bflad bflad deleted the bflad/basetypes-missing-elemtype-panic branch June 12, 2023 14:33
@bflad bflad modified the milestones: v1.4.0, v1.3.1 Jun 13, 2023
@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prevent String() Method Panics When ListType / MapType / SetType ElemType is Not Set
2 participants