[JAVA-687] MongoException should contain the host/port of the server it got an error from Created: 31/Oct/12  Updated: 31/Mar/15  Resolved: 25/Jun/13

Status: Closed
Project: Java Driver
Component/s: Error Handling
Affects Version/s: None
Fix Version/s: 3.0.0

Type: Bug Priority: Major - P3
Reporter: Jeffrey Yemin Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Currently if there is an application error in the server when executing, say, a command, the driver takes the error message from "err" and puts in it a MongoException, so you might see something like:

Caused by: com.mongodb.MongoException: writeback
	at com.mongodb.CommandResult.getException(CommandResult.java:100) ~[mongo.jar:na]
	at com.mongodb.CommandResult.throwOnError(CommandResult.java:134) ~[mongo.jar:na]

It would be useful in many cases to include the host and port of the server that generated the error, e.g.

Caused by: com.mongodb.MongoException: error: writeback, 
                                       server: localhost:30000
	at com.mongodb.CommandResult.getException(CommandResult.java:100) ~[mongo.jar:na]
	at com.mongodb.CommandResult.throwOnError(CommandResult.java:134) ~[mongo.jar:na]



 Comments   
Comment by Jeffrey Yemin [ 31/Mar/15 ]

Closing all resolved 3.0.0 issues, as 3.0.0 has been tagged and released.

Comment by Jeffrey Yemin [ 25/Jun/13 ]

See https://github.com/jyemin/mongo-java-driver/commit/d52fa8a#L2R20.

In 3.0.x branch there is a new class org.mongodb.MongoServerException which contains the ServerAddress as a property.

Comment by Jeffrey Yemin [ 31/Oct/12 ]

The driver doesn't have any more information than this. The server's response to the command is something like:

{
   ok : 0,
   err: "writeback"
}

That said, it would be good to make it very clear that that's the case. Currently the driver does not make it easy to determine whether a message like that is server-side generated or driver-generated (e.g. "can't say something" or "out of semaphores")

Comment by Ryan Nitz [ 31/Oct/12 ]

It might be good to add a bit more information explaining what a writeback exception is #shrug

Generated at Thu Feb 08 08:52:51 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.