Skip to content

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

Open
@austinvalle

Description

@austinvalle

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestreflectionIssues and PRs about the reflection subsystem used to convert between attr.Values and Go values.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions