Skip to content

Error message with potential room for improvement #1387

Open
@bgwines

Description

@bgwines

This concerns the error message

PHP Fatal error:  Uncaught exception 'MongoException' with message 'zero-length keys are not allowed, did you use $ with double quotes?'

I believe in all of the three following scenarios:

  • If you have an @ODM\EmbeddedDocument with an @ODM\Field ivar with a type="hash" annotation but it's actually set to an array-like associative array (integer keys, contiguous from 0 to some n)
  • The reverse case: if you have an @ODM\EmbeddedDocument with an @ODM\Field ivar with a type="collection" annotation but it's actually set to a map-like associative array
  • If you have an @ODM\EmbeddedDocument with an @ODM\Field ivar with a type="collection" annotation, and fill it with @ODM\EmbeddedDocuments (instead of annotating it with @ODM\EmbedMany) (not 100% this is the exception thrown in this case but I think so?)

It would be nice if the exception were to detail which instance variable is the offending one, in which class -- as it currently stands, it's rather unhelpful and time-consuming to debug.

Given how PHP associative arrays unfortunately basically don't distinguish at all between being maps or arrays, as you probably know, it's a pretty easy mistake to make to think you have an array and it's actually map (or the opposite), since it's not enforced at the type level.

Thanks for your attention to this matter! :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions