EventSaucePHP / ObjectHydrator

Object Hydration library to create Command and Query objects.
MIT License
318 stars 24 forks source link

UnableToHydrateObjectException needs more Details about the payload #53

Closed pscheit closed 1 year ago

pscheit commented 1 year ago

Hi there,

really enjoying the object mapper so far. Trying to migrate away from valinor, and currently dont see how to solve this:

When one of my objects is missing a field, I have a hard time figuring out which object it is in the big array of objects:

        try {
            $contracts = $this->objectMapper->hydrateObjects(ContractDto::class, $rows)->toArray();
        } catch (\EventSauce\ObjectHydrator\UnableToHydrateObject $e) {
            dump($rows);
        }

all I have is:

In UnableToHydrateObject.php line 49:

  [EventSauce\ObjectHydrator\UnableToHydrateObject]
  Unable to hydrate object: YAY\Application\Dtos\ContractDto, missing fields: customer_uid

Exception trace:
  at /app/vendor/eventsauce/object-hydrator/src/UnableToHydrateObject.php:49
 EventSauce\ObjectHydrator\UnableToHydrateObject::dueToMissingFields() at /app/vendor/eventsauce/object-hydrator/src/ObjectMapperUsingReflection.php:155

Would be helpful to have at least the full payload of the object where this "dueToMissingFields" was thrown? Or the key/path of the array?

frankdejonge commented 1 year ago

@pscheit Hi, the exception should contain the hydration stack (should maybe have been called path). Does that help you out?

pscheit commented 1 year ago

aijaijai! How did i missed that 🤦 sorry!