hashicorp / hashicorp/terraform-plugin-framework-validators

Better messaging from errors under `Any` validator

Open
#203 0 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Go
Stars
28
Forks
13
Avg merge
2d 13h
Merged PRs (30d)
1

Description

### Terraform CLI and Framework Versions

Terraform v1.5.7
on darwin_amd64

github.com/hashicorp/terraform-plugin-framework v1.6.1

### Use Cases or Problem Statement

I've used the [Any](https://github.com/hashicorp/terraform-plugin-framework-validators/blob/main/stringvalidator/any.go) validator but the error messages that occur are not intuitive for a user. In my case, I've passed 2 possibilities to match and failing to match them shows 2 individual errors for the same line without any indication they are related except for the line number. It's a confusing enough experience that I will instead likely create a custom validator.

### Proposal

One option that may be straightforward to accommodate is to allow passing a custom error message for the Any block that would override an error from one of the validators in the list.

Another option would be to generate a new single error using text appropriate to the Any validator. For example:

Attribute my_attr value did not satisfy any of "value must be one of: ["alternate"]" or "must match UUID format", got: ""...

### Additional Information

I see that this is currently expected behavior as exhibited by the test here:
this output in the test here: https://github.com/hashicorp/terraform-plugin-framework-validators/blob/main/stringvalidator/any_test.go#L35-L45

### Code of Conduct

- [X] I agree to follow this project's Code of Conduct

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.