doctrine / orm

Doctrine Object Relational Mapper (ORM)
https://www.doctrine-project.org/projects/orm.html
MIT License
9.91k stars 2.51k forks source link

DDC-3289: Better exception description on some mapping errors #4080

Open doctrinebot opened 10 years ago

doctrinebot commented 10 years ago

Jira issue originally created by user lmammino:

Mapping problems does not always throw very explicit exceptions.

I had this feeling with a very common error:

{quote} This behaviour is (currently) not supported by Doctrine 2" {quote}

I essentially forgot to add a "mapped-by" attribute in my mappings and, given this generic message, I admit I had to spend a bit of time before being able to spot the mistake.

That's the code that detected the problem and triggered the proper exception.

} elseif ($mapping['type'] == ClassMetadata::ONE*TO*MANY && $mapping['isOwningSide']) {
                //... create join table, one-many through join table supported later
                throw ORMException::notSupported();

Within the $mapping variable I see we have a lot of useful information about the problem. Why don't use them to create a very helpful exception message that reports the exact mapped entity and field that raised the error?

IMHO this will grant a better developer experience, especially for doctrine newcomers!

doctrinebot commented 10 years ago

Comment created by @ocramius:

Hey [~lmammino], could you come up with an exception message that makes sense to you? This kind of improvement is trivial to implement, so it should be quick...

doctrinebot commented 10 years ago

Comment created by lmammino:

Hi [~ocramius] :) I think something like:

{quote} One to Many relationships without "mapped-by" attribute are not allowed. (Found in "\Foo\Bar\SomeEntity", field "somefield") {quote}

Will be good enough to give developers some clue about where the problem lies. Anyway I'm not sure it covers all the possible cases for this exception and that it is consistent with other error messages within the codebase.