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

helper/validation: StringInSlice: Single quote slice elements #1237

Merged
merged 1 commit into from
Aug 29, 2023

Conversation

Frankkkkk
Copy link
Contributor

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

@Frankkkkk Frankkkkk requested a review from a team as a code owner August 29, 2023 09:32
@bflad bflad added the bug Something isn't working label Aug 29, 2023
Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Frankkkkk 👋 Thank you for submitting this change and makes sense in this case. Please note the associated unit test, TestValidationStringInSlice, needs to be updated as well:

--- FAIL: TestValidationStringInSlice (0.00s)
    strings_test.go:283: expected test case 2 to produce error matching "expected [\w]+ to be one of \[ValidValue AnotherValidValue\], got VALIDVALUE", got [expected test_property to be one of ["ValidValue" "AnotherValidValue"], got VALIDVALUE]

Maintainer note: I think this differs from https://github.com/hashicorp/terraform-plugin-framework-validators/pull/152/files because over there, it was %q quoting framework types.String values instead of string.

@Frankkkkk
Copy link
Contributor Author

Hi @bflad thanks for your feed back. Sorry, I forgot to add the test file to the commit :(. It should be fixed.
Thanks !

@Frankkkkk Frankkkkk requested a review from bflad August 29, 2023 12:00
@bflad bflad added this to the v2.29.0 milestone Aug 29, 2023
@bflad
Copy link
Contributor

bflad commented Aug 29, 2023

No worries, @Frankkkkk! If you're interested, this change likely should also have a changelog entry which you can add if you are interested. You can find information about adding one in the contributing guide. Something like "helper/validation: Added quoting in StringInSlice error diagnostic output to prevent confusion with values that contain spaces" -- if that's a little much, we can take care of that post-merge. Thanks again!

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
Copy link
Contributor Author

No problem :-) It should be done.
Cheers

Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks, @Frankkkkk 🚀

@bflad bflad merged commit 09a29d6 into hashicorp:main Aug 29, 2023
6 checks passed
@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve validation.StringInSlice error message
2 participants