Skip to content

Inappropriate error detail for UniqueEntity annotation error #336

@crayner

Description

@crayner

Bug Report

Q A
BC Break No
Version All

Summary

I found an error trying to validate the doctrine schema:

php bin/console doctrine:schema:validate --verbose

Mapping
-------

In Constraint.php line 163:

  [Symfony\Component\Validator\Exception\MissingOptionsException]
  The options "fields" must be set for constraint "Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity".


Exception trace:
  at F:\websites\crayner\quoll\vendor\symfony\validator\Constraint.php:163
 Symfony\Component\Validator\Constraint->normalizeOptions() at F:\websites\crayner\quoll\vendor\symfony\validator\Constraint.php:108
 Symfony\Component\Validator\Constraint->__construct() at F:\websites\crayner\quoll\vendor\doctrine\annotations\lib\Doctrine\Common\Annotations\DocParser.php:827
 Doctrine\Common\Annotations\DocParser->Annotation() at F:\websites\crayner\quoll\vendor\doctrine\annotations\lib\Doctrine\Common\Annotations\DocParser.php:662
 Doctrine\Common\Annotations\DocParser->Annotations() at F:\websites\crayner\quoll\vendor\doctrine\annotations\lib\Doctrine\Common\Annotations\DocParser.php:354
 Doctrine\Common\Annotations\DocParser->parse() at F:\websites\crayner\quoll\vendor\doctrine\annotations\lib\Doctrine\Common\Annotations\AnnotationReader.php:221
 Doctrine\Common\Annotations\AnnotationReader->getClassAnnotations() at F:\websites\crayner\quoll\vendor\doctrine\annotations\lib\Doctrine\Common\Annotations\CachedReader.php:80
 Doctrine\Common\Annotations\CachedReader->getClassAnnotations() at F:\websites\crayner\quoll\vendor\doctrine\persistence\lib\Doctrine\Persistence\Mapping\Driver\AnnotationDriver.php:177
 Doctrine\Persistence\Mapping\Driver\AnnotationDriver->isTransient() at F:\websites\crayner\quoll\vendor\doctrine\persistence\lib\Doctrine\Persistence\Mapping\Driver\AnnotationDriver.php:245
 Doctrine\Persistence\Mapping\Driver\AnnotationDriver->getAllClassNames() at F:\websites\crayner\quoll\vendor\doctrine\persistence\lib\Doctrine\Persistence\Mapping\Driver\MappingDriverChain.php:107
 Doctrine\Persistence\Mapping\Driver\MappingDriverChain->getAllClassNames() at F:\websites\crayner\quoll\vendor\doctrine\persistence\lib\Doctrine\Persistence\Mapping\AbstractClassMetadataFactory.php:90
 Doctrine\Persistence\Mapping\AbstractClassMetadataFactory->getAllMetadata() at F:\websites\crayner\quoll\vendor\doctrine\orm\lib\Doctrine\ORM\Tools\SchemaValidator.php:68
 Doctrine\ORM\Tools\SchemaValidator->validateMapping() at F:\websites\crayner\quoll\vendor\doctrine\orm\lib\Doctrine\ORM\Tools\Console\Command\ValidateSchemaCommand.php:69
 Doctrine\ORM\Tools\Console\Command\ValidateSchemaCommand->execute() at F:\websites\crayner\quoll\vendor\doctrine\doctrine-bundle\Command\Proxy\ValidateSchemaCommand.php:34
 Doctrine\Bundle\DoctrineBundle\Command\Proxy\ValidateSchemaCommand->execute() at F:\websites\crayner\quoll\vendor\symfony\console\Command\Command.php:258
 Symfony\Component\Console\Command\Command->run() at F:\websites\crayner\quoll\vendor\symfony\console\Application.php:929
 Symfony\Component\Console\Application->doRunCommand() at F:\websites\crayner\quoll\vendor\symfony\framework-bundle\Console\Application.php:96
 Symfony\Bundle\FrameworkBundle\Console\Application->doRunCommand() at F:\websites\crayner\quoll\vendor\symfony\console\Application.php:264
 Symfony\Component\Console\Application->doRun() at F:\websites\crayner\quoll\vendor\symfony\framework-bundle\Console\Application.php:82
 Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at F:\websites\crayner\quoll\vendor\symfony\console\Application.php:140
 Symfony\Component\Console\Application->run() at F:\websites\crayner\quoll\bin\console:42

The issue here is not with the error, but in the fact that the error is not correctly identifying the issue, which is a annotation parse error, causing the Contraint violation. Unfortunately, this error does not identify the entity at fault, and I had to remove ALL UniqueEntity references in 150+ entities and return them one at a time to eventually find the error. The error on the annotation looks like:

...
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
...

 * @ORM\Table(name="Scale",
 *     indexes={@ORM\Index(name="lowest_acceptable",columns={"lowest_acceptable"})},
 *     uniqueConstraints={@ORM\UniqueConstraint(name="name",columns={"name"}),
 *     @ORM\UniqueConstraint(name="abbreviation",columns={"abbreviation"}),
 * })
 * @UniqueEntity{"name"})
 * @UniqueEntity({"abbreviation"})

The error is on the "name" line, which is missing the opening bracket.

Current behavior

The current behaviour is as stated above.

How to reproduce

Remove the opening bracket on any UniqueEntity annotation will duplicate this issue.

Expected behavior

[Doctrine\Common\Annotations\AnnotationException]
  [Syntax Error] Failed to see bracket set at position xxx in class App\Entity\Name.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions