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 validation.StringInSlice error message #464

Closed
CyrusJavan opened this issue May 28, 2020 · 1 comment · Fixed by #1237
Closed

Improve validation.StringInSlice error message #464

CyrusJavan opened this issue May 28, 2020 · 1 comment · Fixed by #1237
Labels
enhancement New feature or request

Comments

@CyrusJavan
Copy link

SDK version

{
  "Path": "github.com/hashicorp/terraform-plugin-sdk",
  "Version": "v1.13.0"
}

Use-cases

When using the StringInSlice SchemaValidateFunc with valid strings that contain white spaces.
For example:

ValidateFunc: validation.StringInSlice([]string{"Base Policy", "Allow", "Deny"}, false),

If the user inputs an invalid value the error message looks like

Error: expected domain_names.0.action to be one of [Base Policy Allow Deny], got dont_allow

It is ambiguous whether "Base Policy" is a single phrase or two separate words.

Attempted Solutions

I've written my own version of StringInSlice that separates words by comma. So the error message instead looks like

 Error: expected domain_names.0.action to be one of [Base Policy, Allow, Deny], got dont_allow

Proposal

By default, StringInSlice should separate valid values by comma in the error message. I would be happy to work on this as I've already done it once! 😄

References

None.

@CyrusJavan CyrusJavan added the enhancement New feature or request label May 28, 2020
@ghost
Copy link

ghost commented Dec 31, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked as resolved and limited conversation to collaborators Dec 31, 2020
Frankkkkk added a commit to Frankkkkk/terraform-plugin-sdk that referenced this issue Aug 29, 2023
The validation function's error is ambiguous when dealing with slices
containing spaces. For example:
```
expected role_name to be one of [Apache Spark Administrator Synapse Credential User Synapse Administrator]
```

By changing the format verb, the error becomes more user friendly:
```
expected role_name to be one of ["Apache Spark Administrator" "Synapse Credential User" "Synapse Administrator"]
```

This fixes hashicorp#464

Signed-off-by: Frank Villaro-Dixon <frank.villarodixon@merkle.com>
Frankkkkk added a commit to Frankkkkk/terraform-plugin-sdk that referenced this issue Aug 29, 2023
The validation function's error is ambiguous when dealing with slices
containing spaces. For example:
```
expected role_name to be one of [Apache Spark Administrator Synapse Credential User Synapse Administrator]
```

By changing the format verb, the error becomes more user friendly:
```
expected role_name to be one of ["Apache Spark Administrator" "Synapse Credential User" "Synapse Administrator"]
```

This fixes hashicorp#464

Signed-off-by: Frank Villaro-Dixon <frank.villarodixon@merkle.com>
Frankkkkk added a commit to Frankkkkk/terraform-plugin-sdk that referenced this issue Aug 29, 2023
The validation function's error is ambiguous when dealing with slices
containing spaces. For example:
```
expected role_name to be one of [Apache Spark Administrator Synapse Credential User Synapse Administrator]
```

By changing the format verb, the error becomes more user friendly:
```
expected role_name to be one of ["Apache Spark Administrator" "Synapse Credential User" "Synapse Administrator"]
```

This fixes hashicorp#464

Signed-off-by: Frank Villaro-Dixon <frank.villarodixon@merkle.com>
bflad pushed a commit that referenced this issue Aug 29, 2023
The validation function's error is ambiguous when dealing with slices
containing spaces. For example:
```
expected role_name to be one of [Apache Spark Administrator Synapse Credential User Synapse Administrator]
```

By changing the format verb, the error becomes more user friendly:
```
expected role_name to be one of ["Apache Spark Administrator" "Synapse Credential User" "Synapse Administrator"]
```

This fixes #464

Signed-off-by: Frank Villaro-Dixon <frank.villarodixon@merkle.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant