[SERVER-3387] getLastErrorDetailed does not report an error Created: 07/Jul/11  Updated: 29/Aug/11  Resolved: 07/Jul/11

Status: Closed
Project: Core Server
Component/s: Internal Client
Affects Version/s: 1.8.1
Fix Version/s: None

Type: Bug Priority: Critical - P2
Reporter: Alexey Guseynov Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

linux, ubuntu lucyd.


Operating System: ALL
Participants:

 Description   

Request:
{ "findAndModify" : "points", "query" :

{ "_id" : "b91bb726-fe07-5c37-92e7-56077fbc2b36", "version" : 0 }

, "update" : { "$set" :

{ < SOME FIELDS HERE > }

}, "new" : true, "upsert" : false }
Result:

{ "errmsg" : "No matching object found", "ok" : 0 }

As far as mongo C++ driver does not throw exceptions and every command has it's own way to report errors I prefer to use getLastErrorDetailed() where possible. But unfortunately it reports that there was no error:

{ "n" : 0, "connectionId" : 88, "err" : null, "ok" : 1 }

Please, make C++ driver to report error is only one way. It would especially good if it would be exceptions. I'm really frustrated to find out that one part of my application has crashed with very strange error because there is another one way to report error which my magic checker does not know about.



 Comments   
Comment by Eliot Horowitz (Inactive) [ 07/Jul/11 ]

I was thinking of this command for running findAndModify
virtual bool runCommand(const string &dbname, const BSONObj& cmd, BSONObj &info, int options=0);

Updated the docs for getLastError

Comment by Alexey Guseynov [ 07/Jul/11 ]

> For commands (findAndModify etc...) the method returns true or false if succeeded or not.
> That is the correct thing to do for those.

Actually, it does not return true or false. It returns BSON object which has double precision flag. It is if you would try to check it for beeng true or false you would get "wrong BSON type" exception.

> The only things you need getLastError for are insert/update/delete.

Both 1.9.0 and 1.8.1 API documentation say:
Get error result from the last operation on this connection.

So I does not work as designed. Please reopen the bugreport or change documentation to reflect that sometimes getLastError returns last error and sometimes it doesn't.

Comment by Eliot Horowitz (Inactive) [ 07/Jul/11 ]

This is correct for normal mode.
In safe mode it will throw exceptions for errors.

Comment by Eliot Horowitz (Inactive) [ 07/Jul/11 ]

For commands (findAndModify etc...) the method returns true or false if succeeded or not.
That is the correct thing to do for those.

The only things you need getLastError for are insert/update/delete.

We're going a "safe" mode to the driver which will use exceptions: SERVER-1384

Generated at Thu Feb 08 03:02:55 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.