validator icon indicating copy to clipboard operation
validator copied to clipboard

Add type to incorrect input messages

Open arogachev opened this issue 3 years ago • 10 comments

Currently:

https://github.com/yiisoft/validator/blob/e3a6c11847f550a5ed39eb1254b06b04331dd3d5/src/Rule/AtLeast.php#L38

Added recently:

https://github.com/yiisoft/validator/blob/dfdf19e71f83931d2a62b48a9d7f41eee79d2461/src/Rule/BoolValue.php#L83

Funding

  • You can sponsor this specific effort via a Polar.sh pledge below
  • We receive the pledge once the issue is completed & verified
Fund with Polar

arogachev avatar Dec 26 '22 07:12 arogachev

Are these messages intended to be shown to end users? I understand validation message in case of an API, when it is shown to a developer. In case of a HTML form, this messages happing sounds like a programming error and should rather be an excepction than a message shown to the user.

cebe avatar Feb 03 '23 09:02 cebe

@cebe See the 2nd part of response here - https://github.com/yiisoft/validator/pull/514#discussion_r1092912975. At some point there were such exceptions. But then we discussed it and decided that handlers should not throw exceptions related with wrong input data. @vjik

arogachev avatar Feb 03 '23 11:02 arogachev

@cebe You are suggesting to be able to configure different behavior for API (throw exceptions) and forms (show messages), right?

arogachev avatar Feb 03 '23 11:02 arogachev

Kind of related - #526.

arogachev avatar Feb 03 '23 11:02 arogachev

Throw exception is not validator task. If it need, then should be code that process validator results and throw exception if need.

vjik avatar Feb 03 '23 11:02 vjik

Not sure about the correct solution but the point here is to differentiate between validation messages for a user and error messages for the programmer.

Definition:

Validation message for a user is a message displayed for the user that the user can understand and most importantly allows the user to fix the input.

Error message for the programmer is a message that comes up when the validator is fed with data that can not appear in normal circumstances when users are filling the form, but somehow happen due to an error in the program. In this case the user is very likely not able to correct the input themselfs because the program has a bug. It does not make sense to show these messages to the user.

cebe avatar Feb 08 '23 11:02 cebe

Changed the milestone as I consider this a major design issue in how a validation library should work.

cebe avatar Feb 08 '23 11:02 cebe

@cebe This issue is only about providing more details in the error message by adding the extra parameter. Created a separate issue - #546.

arogachev avatar Feb 09 '23 06:02 arogachev

@cebe what do you want to do with these errors? Would you somehow handle it differently from the rest of validation errors? Would you hide these from end users?

samdark avatar Feb 09 '23 07:02 samdark

@samdark answered in https://github.com/yiisoft/validator/issues/546#issuecomment-1423891838

cebe avatar Feb 09 '23 09:02 cebe

Done by #736

vjik avatar Jul 31 '24 07:07 vjik