Keats / validator

Simple validation for Rust structs
MIT License
2k stars 144 forks source link

Why each errors starts with the word (Error:) #291

Closed HosMercury closed 7 months ago

HosMercury commented 7 months ago

I have this validation

#[derive(Debug, Clone, Deserialize, Validate)]
pub struct SignUp {
    #[validate(
        length(min = 4, message = "Name must be greater than 4 chars"),
        regex(
            path = "REGEX_USERNAME",
            message = "Name must be alphanumeric and/or dashes only"
        )
    )]
    pub name: String,

    #[validate(
        length(min = 4, message = "Username must be greater than 4 chars"),
        regex(
            path = "REGEX_USERNAME",
            message = "Username must be alphanumeric and/or dashes only"
        )
    )]
    pub username: String,

    #[validate(
        length(min = 4, message = "Password must be more than 4 letters"),
        custom(
            function = "validate_password",
            message = "Password must be 4-50 characters long, contain letters and numbers, and must not contain spaces, special characters, or emoji"
        )
    )]
    pub password: String,

    #[validate(must_match(other = "password", message = "Passwords are not identical"))]
    pub password2: String,
}

But why every error starts with Error: ?

This is the resulted errors

Error: Password must be 4-50 characters long, contain letters and numbers, and must not contain spaces, special characters, or emoji

Error: Name must be alphanumeric and/or dashes only

?

HosMercury commented 7 months ago

it was my bad