Validation icon indicating copy to clipboard operation
Validation copied to clipboard

Inconsistent Exception messages

Open nipunadodan opened this issue 4 years ago • 0 comments

It's an awesome library to leave for this hard to get right Exception handling and painful documentations. I've got getFullMessage() returned as expected but it's just as a String. $e->getMessages() only outputs one error message from one key/attribute, which shouldn't be the case.

$postValidator = Valid::attribute('title',Valid::length(2,3)->stringType())
            ->attribute('description',Valid::stringType())
            ->attribute('author',Valid::intType()->length(1,2))
            ->attribute('user',Valid::intVal()->length(1,2));
try {
    $postValidator->assert($input);
} catch (NestedValidationException $e) {
    echo json_encode($e->getMessages());
}

With $e->getMessages() (after json_encoded)

{
    "title": "title must be of type string",
    "author": "author must have a length between 1 and 2",
    "user": "Attribute user must be present"
}

With $e->getFullMessage()

 - All of the required rules must pass for title\n    
    - title must have a length between 2 and 3\n    
    - title must be of type string\n  
 - All of the required rules must pass for author\n    
    - author must be of type integer\n    
    - author must have a length between 1 and 2\n    
 - Attribute user must be present

The later has more information. Is there a way I can get all of the information shown with $e->getMessages()? Moreover, I think this is a bug. Isn't it?

nipunadodan avatar Jan 15 '22 12:01 nipunadodan