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

Way to redefine error messages #48

Open
lud4ik opened this issue Feb 10, 2019 · 6 comments
Open

Way to redefine error messages #48

lud4ik opened this issue Feb 10, 2019 · 6 comments

Comments

@lud4ik
Copy link
Contributor

lud4ik commented Feb 10, 2019

I have a scheme of t.Dict with several fields. I want when required field is absent to replace default error string. What is the best way to do it? without kostyls...

@Arfey
Copy link
Collaborator

Arfey commented Feb 11, 2019

U can redefine base clases.

class MyBool(t.Bool):
    def check_value(self, value):
        if not isinstance(value, bool):
            self._failure("My custom error", value=value)

MyBool().check(True)

or user t.Call

def not_some_validator(value):
    if value == "some":
        return t.DataError('My custom error.')
    return value

t.Call(not_some_validator).check("some")

I'm not sure what is the best way but it's not look like "kostyls"

@Deepwalker
Copy link
Owner

I need some time to figure out proper way.

@lud4ik
Copy link
Contributor Author

lud4ik commented Mar 1, 2019

а можна ли разширить так чтобы все текста ошибок можна было переопределять?
к примеру если t.Int(gt=0) при 0 задать "Please enter non-zero value"

@Deepwalker
Copy link
Owner

можно, на выходных постараюсь сделать

@hzlmn
Copy link

hzlmn commented Dec 11, 2019

Привет, это еще актуально? Тоже интересует ..

@Deepwalker
Copy link
Owner

In version2 DataError has code field and to_struct method that returns code as well as message. It can be used with any localisation library. I think this should solve localisation problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants