neos / flow-development-collection

The unified repository containing the Flow core packages, used for Flow development.
https://flow.neos.io/
MIT License
137 stars 189 forks source link

BUG: `Result::getFirstError` can return `false` even if `Result::hasErrors` is true #3370

Open mhsdesign opened 3 months ago

mhsdesign commented 3 months ago

State of the result in question

Flow Variable Dump
Neos\Error\Messages\Result object
 errors => array(empty)
 errorsExist => true
 warnings => array(empty)
 warningsExist => false
 notices => array(empty)
 noticesExist => false
 propertyResults => array(1)
   integer 0 => Neos\Error\Messages\Result object
     errors => array(1)
       integer 0 => Neos\Flow\Property\TypeConverter\Error\TargetNotFoundError prototype object proxy
     errorsExist => true
     warnings => array(empty)
     warningsExist => false
     notices => array(empty)
     noticesExist => false
     propertyResults => array(empty)
     parent => Neos\Error\Messages\Result object
 parent => NULL

The following code breaks with this exception, and after debugging it turns out getFirstError really returns false.

Error: Call to a member function getMessage() on bool

$propertyValue = $this->propertyMapper->convert(...);
$messages = $this->propertyMapper->getMessages();
if ($messages->hasErrors()) {
    throw new \RuntimeException($messages->getFirstError()->getMessage(), 1718976491);
}

This seems to be a workaround to really get the first error:

$flattenedErrors = $messages->getFlattenedErrors();
$firstError = current(current($flattenedErrors));

I think this is because we set errorsExist on the parent but the error i inside the propertyResults sub result. Maybe this is how it is and im using it wrongly.

Tested on

Flow 7.3 Flow 8.3