-
Notifications
You must be signed in to change notification settings - Fork 91
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
incorrect handling of nil pointer receiver in Diagnostics.Append
#932
Comments
diagnostics.Append
Diagnostics.Append
Hi @john-behm-bertelsmann 👋 Thank you for reporting this. Did you encounter this as an issue when writing provider code or are you reporting this as a potential gotcha that someone might run into? |
It's more of a gotcha that I stumbled upon when looking at the Diagnostics implementation while implementing a provider but not running into any issues with this. The package internal_test
import (
"testing"
"github.com/hashicorp/terraform-plugin-framework/diag"
)
// Is impossible in any case
func TestDiagnosticsAppend01(t *testing.T) {
t.Parallel()
defer func() {
i := recover()
if i == nil {
t.Fatal("expected panic")
}
}()
var d *diag.Diagnostics = nil
d.Append(diag.NewErrorDiagnostic("error", "error message"))
}
// Is possible
func TestDiagnosticsAppend02(t *testing.T) {
t.Parallel()
defer func() {
i := recover()
if i != nil {
t.Fatal("expected no panic")
}
}()
var d diag.Diagnostics = nil
d.Append(diag.NewErrorDiagnostic("error", "error message"))
} The "correct" implementation would panic as well, because it's not possible to do that. |
Thank you for that additional context, @john-behm-bertelsmann! Would you like to submit the code fix for this? |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
It's not possible to handle the case when the receiver is nil in line 47 which is then a nil pointer to a slice (pointer).
This line is not covered by tests, as it is incorrect and impossible to handle.
It gives a false sense of that such a case can be handled, which it cannot.
terraform-plugin-framework/diag/diagnostics.go
Lines 37 to 53 in f35653e
The text was updated successfully, but these errors were encountered: