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

Improve reflection error messaging for unexported fields with tfsdk tags #866

Open
austinvalle opened this issue Oct 26, 2023 · 0 comments
Labels
enhancement New feature or request reflection Issues and PRs about the reflection subsystem used to convert between attr.Values and Go values. tf-devex-triage Terraform DevEx project tracking

Comments

@austinvalle
Copy link
Member

austinvalle commented Oct 26, 2023

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
@austinvalle austinvalle added enhancement New feature or request reflection Issues and PRs about the reflection subsystem used to convert between attr.Values and Go values. tf-devex-triage Terraform DevEx project tracking labels Oct 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request reflection Issues and PRs about the reflection subsystem used to convert between attr.Values and Go values. tf-devex-triage Terraform DevEx project tracking
Projects
None yet
Development

No branches or pull requests

1 participant