terraform-plugin-framework
terraform-plugin-framework copied to clipboard
Improve reflection error messaging for unexported fields with `tfsdk` tags
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:
type resourceModel struct {
id types.Int64 `tfsdk:"id"`
description types.String `tfsdk:"description"`
}
mismatch between struct and object: Object defines fields not found in struct: <list of fields>
Proposal
Adjust the reflection error message to describe the exact fields that are invalid (unexported with a tfsdk
tag, maybe other errors?)
type resourceModel struct {
id types.Int64 `tfsdk:"id"`
description types.String `tfsdk:"description"`
}
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