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

[BUG] Enum-related validation error messages contain numbers instead of value names #125

Closed
mithRabbit opened this issue May 23, 2024 · 1 comment
Labels
Bug Something isn't working

Comments

@mithRabbit
Copy link

mithRabbit commented May 23, 2024

Description

enum validation message is not correct

Steps to Reproduce

  1. write proto message
    enum IDType {
    ID_TYPE_UNSPECIFIED = 0;
    ID_TYPE_PASSPORT = 1;
    ID_TYPE_TAX_ID = 2;
    }

    // ID type. Must be ID_TYPE_PASSPORT or ID_TYPE_TAX_ID.
    // IDType id_type = 1 [(google.api.field_behavior) = REQUIRED, (buf.validate.field).enum = {in: [1,2]}];

  2. build the protobuf

  3. run the validator
    v, err := protovalidate.New()
    if err != nil {
    panic(err)
    }

    if err := v.Validate(req); err != nil {
    panic(err)
    }

Expected Behavior

id_type : value must be in list [ID_TYPE_PASSPORT , ID_TYPE_TAX_ID]

Actual Behavior

ID_TYPE_PASSPORT or ID_TYPE_TAX_ID

Screenshots/Logs

Screenshot 2567-05-23 at 16 39 51

Environment

  • Operating System: macos>

  • Version: sonoma Version 14.4.1 (23E224)

  • Compiler/Toolchain: <go 1.22.2>
    // - protoc-gen-go-grpc v1.3.0
    // - protoc v4.23.4

  • Protovalidate Version: v0.6.2

Possible Solution

Additional Context

@mithRabbit mithRabbit added the Bug Something isn't working label May 23, 2024
@rodaine
Copy link
Member

rodaine commented May 23, 2024

Unfortunately, CEL does not preserve details about the enum itself (like value names) and is only capable of preserving the integer values of the enum types. For all enum related rules you'll see error messages presenting the integer value as this is a limitation of CEL.

@rodaine rodaine closed this as not planned Won't fix, can't repro, duplicate, stale May 23, 2024
@rodaine rodaine changed the title [BUG] [BUG] Enum-related validation error messages contain numbers instead of value names May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants