Commit c0654989 authored by Guillaume Perréal's avatar Guillaume Perréal

Rend bloquantes les erreurs de mapping.

Mais améliore les messages d'erreurs.
parent 6873ed0f
......@@ -269,8 +269,8 @@ final class ModelGenerator
if ($repo) {
$repositories[$repo->getName()] = $repo;
}
} catch (Exception $ex) {
printf("Error while mapping %s: %s\n%s\n", $class, $ex->getMessage(), $ex->getTraceAsString());
} catch (\Throwable $ex) {
throw new DomainException(sprintf('error with resource `%s`: %s', $resourceMeta->getBaseName(), $ex->getMessage()), 0, $ex);
}
}
......
......@@ -103,21 +103,33 @@ final class SerializationMapper implements TypeFactoryInterface
{
if (class_exists($name)) {
$class = PHPClass::get($name);
if ($this->serialization->hasRepresentationOf($class)) {
$repr = $this->serialization->getRepresentationOf($class);
return $this->defer($repr->getName())
->resolveWith(
function () use ($repr) {
return $this->mapRepresentation($repr);
}
);
return $this->deferredMapping($name, $repr->getName(), function () use ($repr) {
return $this->mapRepresentation($repr);
});
}
}
return $this->typeFactory->get($name);
}
private function deferredMapping(string $name, string $actualName, callable $mapper): Type
{
return $this->defer($actualName)
->resolveWith(
function () use ($name, $mapper) {
try {
return $mapper();
} catch (\Throwable $ex) {
throw new DomainException(sprintf('error with %s: %s', $name, $ex->getMessage()), 0, $ex);
}
}
);
}
public function getResourceData(): array
{
$resource = $this->serialization->getRoot();
......
......@@ -56,7 +56,7 @@ final class TypeFactory implements TypeFactoryInterface, \IteratorAggregate
}
if (!isset($this->types[$name])) {
throw new TypeNotFoundException("unknown type ${name}");
throw new TypeNotFoundException("type not defined: ${name}");
}
return $this->types[$name];
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment