Skip to content

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

Merged
bflad merged 1 commit into
hashicorp:mainfrom
Frankkkkk:main
Aug 29, 2023
Merged

helper/validation: StringInSlice: Single quote slice elements#1237
bflad merged 1 commit into
hashicorp:mainfrom
Frankkkkk:main

Conversation

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

No problem :-) It should be done.
Cheers

Copy link
Copy Markdown
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
@github-actions
Copy link
Copy Markdown

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