If you call entity_uri without passing it an entity, then it will throw an EntityMalformedException (actually thrown in entity_extract_ids but not caught).

This should either:
1) Detect the missing entity and throw a more relevant exception; or
2) Return NULL, as it would if you pass an entity without a URL.

I'm happy to write a patch to do either of the above, but I'm new to Drupal so I was looking for some guideance on which option would be best practise.

Comments

nick_schuch’s picture

In my opinion I would do some description of a try catch statement that returned NULL.

Damien Tournoud’s picture

Status: Active » Postponed (maintainer needs more info)

How is the current behavior not desirable?

You pass entity_uri() something that is not an entity, and entity_uri() is replying "I cannot extract an id, vid and bundle from what you gave me". This sounds correct.

ianthomas_uk’s picture

Status: Postponed (maintainer needs more info) » Active

To me that exception implies that I have an entity, it just doesn't have the necessary information, so I would then start trying to work out why it didn't have that information rather than why it wasn't being passed.

This might be something that's obvious to an experienced Drupal dev, but it wasn't obvious to me.

Maybe the correct solution would be for entity_extract_ids to throw an InvalidArgumentException is $entity is empty?