Skip to content

Improve validation.StringInSlice error message #464

@CyrusJavan

Description

@CyrusJavan

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions