hashicorp / hashicorp/terraform-plugin-framework
Improve reflection error messaging for unexported fields with `tfsdk` tags
- Dominant language
- Go
- Stars
- 384
- Forks
- 107
- Avg merge
- 3m
- Merged PRs (30d)
- 1
Description
## Background
For the reflection package, the error message when there are mismatched/unexported fields for building a struct with `tfsdk` tags can be confusing.
It is possible that a field name might accidentally not be exported, but still have a `tfsdk` tag attached to it, like below:
```go
type resourceModel struct {
id types.Int64 `tfsdk:"id"`
description types.String `tfsdk:"description"`
}
```
```bash
mismatch between struct and object: Object defines fields not found in struct:
```
## Proposal
Adjust the reflection error message to describe the exact fields that are invalid (unexported with a `tfsdk` tag, maybe other errors?)
```go
type resourceModel struct {
id types.Int64 `tfsdk:"id"`
description types.String `tfsdk:"description"`
}
```
```bash
mismatch between struct and object: unexported 'id' field found with `tfsdk` tag, consider exporting this field or removing the `tfsdk` tag
mismatch between struct and object: unexported 'description' field found with `tfsdk` tag, consider exporting this field or removing the `tfsdk` tag
```
Contributor guide
Assessment
This issue has not been assessed yet.