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

Separate technical and non-technical error messages #546

Open
arogachev opened this issue Feb 9, 2023 · 8 comments
Open

Separate technical and non-technical error messages #546

arogachev opened this issue Feb 9, 2023 · 8 comments

Comments

@arogachev
Copy link
Contributor

arogachev commented Feb 9, 2023

Extracted from #492 (comment). This was discussed before. The topic raised again by @cebe.

Related - #526.

@samdark
Copy link
Member

samdark commented Feb 9, 2023

I see two potential outcomes:

  1. We won't translate such messages always returning these in English. That's less work for translators but is questionable by itself. What if that's API and I want these messages translated?
  2. Developer will be able to handle such messages in a special way. But I have no idea how. Maybe @cebe can shed a light on this matter...

@BoShurik
Copy link

BoShurik commented Feb 9, 2023

FYI, in symfony such cases generate exceptions not violations (e.g. https://github.com/symfony/validator/blob/6.2/Constraints/BicValidator.php#L69)

@samdark
Copy link
Member

samdark commented Feb 9, 2023

I don't think it is a correct behavior since validator is meant to validate data that could be incorrect, not to throw exceptions.

@cebe
Copy link
Member

cebe commented Feb 9, 2023

Exceptions should only be thrown if the error is not caused by the user input itself, but it is hard to figure out when this is the case.

Example: String Validator Max Length=30 gets an array. On a HTML form with a normal input field this can not happen so if this happens we can not tell the user to "please do not enter an array here". This somehow ended up in the program so it should be an exception.

But figuring out in which cases to throw an exception or provide validation error is a tricky thing. I'll try to think about possible solutions.

@samdark
Copy link
Member

samdark commented Feb 9, 2023

On a HTML form with a normal input field this can not happen so if this happens we can not tell the user to "please do not enter an array here".

If that won't happen, why should we worry?

@vjik
Copy link
Member

vjik commented Feb 9, 2023

Example: String Validator Max Length=30 gets an array. On a HTML form with a normal input field this can not happen so if this happens we can not tell the user to "please do not enter an array here". This somehow ended up in the program so it should be an exception.

Two reasons:

  1. User pass array instead of string (little hacker 😎). Technial message "please do not enter an array here" is OK.

  2. Programmer don't prepare user input… But it's business logic. If programmer want prepare data — let him do it.

@BoShurik
Copy link

BoShurik commented Feb 9, 2023

In case of "little hacker" it's better to additionally log such request

@vjik
Copy link
Member

vjik commented Feb 9, 2023

In case of "little hacker" it's better to additionally log such request

My thoughts for implementation:

  1. Add to validation errors property code with unique code by each error types (uuid ?). It's necessary in order to distinguish specific messages (e. g., message about string is more length).

  2. Add to validation errors ability set flags (e. g., "unsupported value type").

  3. Create validator decorator, that will be process validation errors and do what the programmer wants (log when has errors "unsuported value type" or something else).

@arogachev arogachev added severity:BC breaking Breaks backwards compatibility and removed severity:BC breaking Breaks backwards compatibility labels May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants