Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-5423

Improve DocumentNotFound error resolution language

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 8.0.1
    • Affects Version/s: None
    • Component/s: None
    • None

      Regarding the following error message (and related document_not_found, etc. errors)

              no_documents_found:
                resolution: "Create a document of class %{klass} or use a finder
                  method that returns nil when no documents are found instead of
                  raising an exception."

      Two things I see that could be improved:

      1. The suggested primary resolution of "Create a document..." is actually the least common resolution for this issue. Usually, the issue occurs because of criteria scoping, e.g. People.where(name: "Bob").take!. In this case, the correct resolution is most often to change the underlying query criteria (e.g. People.where(first_name: "Bob").take!) rather than creating a new document. If I can't find "Bob", I don't just create a new "Bob" out of thin air 😂

      2. Suggest to remove "that returns nil". Should not assume the return type of possible alternate finder methods. Though all such finder methods do return nil today, the key point is that the alternate method must not raise an exception when no documents are found, not which value it returns in this case (e.g. nil[]:not_found404, etc. would all conceivably work.)

            Assignee:
            Unassigned Unassigned
            Reporter:
            shields@tablecheck.com Johnny Shields
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: