[JCBC-140] Code breaks when Connection URI is improper Created: 07/Nov/12  Updated: 24/Jan/13  Resolved: 15/Jan/13

Status: Closed
Project: Couchbase Java Client
Component/s: Core
Affects Version/s: 1.1-dp3
Fix Version/s: 1.1.1
Security Level: Public

Type: Improvement Priority: Major
Reporter: Deepti Dawar Assignee: Deepti Dawar
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment: 1939 - <manifest><remote name="couchbase" fetch="git://github.com/couchbase/"/><remote name="membase" fetch="git://github.com/membase/"/><remote name="apache" fetch="git://github.com/apache/"/><remote name="erlang" fetch="git://github.com/erlang/"/><default remote="couchbase" revision="master"/><project name="tlm" path="tlm" revision="12abea946eafd7411273d18a10ae1f84390db3d4"><copyfile src="Makefile.top" dest="Makefile"/></project><project name="bucket_engine" path="bucket_engine" revision="70b3624abc697b7d18bf3d57f331b7674544e1e7"/><project name="ep-engine" path="ep-engine" revision="68e3f7c57ae40c42dcb94e4d282bbd1648f9adc0"/><project name="libconflate" path="libconflate" revision="2cc8eff8e77d497d9f03a30fafaecb85280535d6"/><project name="libmemcached" path="libmemcached" revision="ca739a890349ac36dc79447e37da7caa9ae819f5" remote="membase"/><project name="libvbucket" path="libvbucket" revision="00d3763593c116e8e5d97aa0b646c42885727398"/><project name="membase-cli" path="membase-cli" revision="7fe4121e7e83952a4cb032e25a2cb9fca1709354" remote="membase"/><project name="memcached" path="memcached" revision="7ea975a93a0231393502af4ca98976eee8a83386" remote="membase"/><project name="moxi" path="moxi" revision="52a5fa887bfff0bf719c4ee5f29634dd8707500e"/><project name="ns_server" path="ns_server" revision="315aa6af297d7139c505e2fa9aa31dd429615a7d"/><project name="portsigar" path="portsigar" revision="1bc865e1622fb93a3fe0d1a4cdf18eb97ed9d600"/><project name="sigar" path="sigar" revision="63a3cd1b316d2d4aa6dd31ce8fc66101b983e0b0"/><project name="couchbase-examples" path="couchbase-examples" revision="544688dc56420faaf6f25946dd4b3ef3f7c15286"/><project name="couchbase-python-client" path="couchbase-python-client" revision="006c1aa8b76f6bce11109af8a309133b57079c4c"/><project name="couchdb" path="couchdb" revision="b68b5f40e0911db7de651b457e6a79a5937ff810"/><project name="couchdbx-app" path="couchdbx-app" revision="1130fa3c1f117527b761497cfa0c15a1e9968808"/><project name="couchstore" path="couchstore" revision="b5937c4479bf05dcc67264efe19abaf52870a127"/><project name="geocouch" path="geocouch" revision="849d5443689b1924f097548af864c539bffcc929"/><project name="mccouch" path="mccouch" revision="88701cc326bc3dde4ed072bb8441be83adcfb2a5"/><project name="testrunner" path="testrunner" revision="c4e82c929b3c7f2328f234fc9d79b38868268455"/><project name="otp" path="otp" revision="b6dc1a844eab061d0a7153d46e7e68296f15a504" remote="erlang"/><project name="icu4c" path="icu4c" revision="26359393672c378f41f2103a8699c4357c894be7" remote="couchbase"/><project name="snappy" path="snappy" revision="5681dde156e9d07adbeeab79666c9a9d7a10ec95" remote="couchbase"/><project name="v8" path="v8" revision="447decb75060a106131ab4de934bcc374648e7f2" remote="couchbase"/><project name="gperftools" path="gperftools" revision="8f60ba949fb8576c530ef4be148bff97106ddc59" remote="couchbase"/><project name="pysqlite" path="pysqlite" revision="0ff6e32ea05037fddef1eb41a648f2a2141009ea" remote="couchbase"/></manifest>

Attachments: Java Source File ConfigurationParserJSON.java     File couchbase_SDK_connect_exception.odt    

 Description   
The code breaks abruptly when connection URI is not given in a proper format in the SDK client for connecting the to required Couchbase server.
For instance, when I am specifying the URI as "http:/10.3.2.57:8091/index.html" instead of "http:/10.3.2.57:8091/pools", exception appears,
whereas a proper error message should be returned saying that 'Connection could not be established to the requested server location'.
Please find attached the log file for the exception trace.

 Comments   
Comment by Michael Nitschinger [ 08/Nov/12 ]
Deepti,

I think the logs already provide a helpful error message with the stack trace that shows what it tried to parse.

In the case you provided, the logs would say 2012-11-08 10:29:09.254 WARN com.couchbase.client.vbucket.ConfigurationProviderHTTP: Provided URI http://192.168.1.105:8091/index.html has an unparsable response...skipping

and then print a stack trace of what was tried to parse (in this case hughe chunks of HTML).

Also, if you pass in more URIs it would try to get the next one to establish a successful connection.

I think we could catch it and add a different error message, but then it wont be clear to the user what happened.

If you think we really should change something here, please reopen the issue and then we can discuss it together at a broader audience!

Thanks,
Michael
Comment by Deepti Dawar [ 08/Nov/12 ]
Dear Michael,

As discussed with you, I think the exception here should be caught in a very generic manner that gives the user some information like this - "Connection could not be established - Either the URI provided is incorrect or the host is unavailable". As the user is not concerned about what is happening beyond the scene and not in the least about what is getting parsed in order for the connection to be established. He is just concerned about the system URL he wants to connect to and the network. Either of these two if unavailable with cause an issue in connection, only that needs to be highlighted back to the user in form of a warning message. It should not abruptly break the code. Hence, I am reopening this defect for further investigation.

Regards,
Deepti
Comment by Deepti Dawar [ 26/Dec/12 ]
File changed.
Please approve for check in.
Comment by Deepti Dawar [ 02/Jan/13 ]
Hi Michael,

Please review at

http://review.couchbase.org/#/c/23648/2

Regards,
Deepti
Comment by Mark Nunberg [ 02/Jan/13 ]
I think this should be converted to some kind of connection or execution exception, providing more detailed information.
Comment by Deepti Dawar [ 08/Jan/13 ]
Mark, can we have any exceptions like DisplayableException which could be shown to the end user ?

Can you please give details about the connection or execution exceptions.
Comment by Mark Nunberg [ 08/Jan/13 ]
What is displayed to the user is a sub-component of logging and not of the exception itself. An exception is not an exception unless it represents an exceptional condition; it is up to the code catching the exception to convert this to something the user can understand.

I am not sure if the Couchbase Java client has classes for "connection" exceptions which indicate a difficulty in communication between client and server, but if there isn't such a class then it should be created.

Theroetically

class CouchbaseConnectionException extends Exception {
    ....
}

Typically it seems most of the Couchbase exceptions in the Java client are RuntimeExceptions or ExecutionExceptions (i.e. generic "unchecked" exceptions).

Matt and Michale might have more knowledge of the various classes contained therein and their suitability of use.
Comment by Deepti Dawar [ 09/Jan/13 ]
I agree. There should be in-house exception classes meant to facilitate this purpose.
A user working with couchbase sdk, should have the feasibility of using those exception classes for understanding various scenarios and then acting accordingly.

Please let us know if there are any exception classes for communicating the connection exception to the user in which we can embed a custom message stating what happened.
Comment by Deepti Dawar [ 15/Jan/13 ]
Please review at

http://review.couchbase.org/#/c/23648/
Comment by Deepti Dawar [ 15/Jan/13 ]
Changes checked in for review in gerrit.
Generated at Wed Aug 20 11:35:55 CDT 2014 using JIRA 5.2.4#845-sha1:c9f4cc41abe72fb236945343a1f485c2c844dac9.