-
Type:
Improvement
-
Resolution: Fixed
-
Priority:
Unknown
-
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_found, 404, etc. would all conceivably work.)