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

Open
opened 2026-01-22 14:34:39 +01:00 by admin · 2 comments
Owner

Originally created by @doctrinebot on GitHub (Aug 31, 2014).

Originally assigned to: @beberlei on GitHub.

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!

Originally created by @doctrinebot on GitHub (Aug 31, 2014). Originally assigned to: @beberlei on GitHub. 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!
admin added the Improvement label 2026-01-22 14:34:39 +01:00
Author
Owner

@doctrinebot commented on GitHub (Sep 1, 2014):

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 on GitHub (Sep 1, 2014): 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...
Author
Owner

@doctrinebot commented on GitHub (Sep 1, 2014):

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.

@doctrinebot commented on GitHub (Sep 1, 2014): 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.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#4069