-
Notifications
You must be signed in to change notification settings - Fork 22
Catch run-time and compile-time server exceptions #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work
Please see my comments.
Also, is there any difference between runtime and compile-time (syntax error) exceptions?
| contextedRedisGraph.setRedisGraphCaches(caches); | ||
| return contextedRedisGraph.sendQuery(graphId, preparedQuery); | ||
| } | ||
| catch (Exception e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this try-catch clause please, as it does nothing
| this.cache = cache; | ||
|
|
||
| // If a run-time error occured, the last member of the rawResponse will be a JedisDataException. | ||
| if (rawResponse.get(rawResponse.size()-1) instanceof JedisDataException) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
few questions:
- Isn't a JedisDataException thrown, and not returned?
- If the exception is returned, don't you think it is better to define our own exception class such as JRedisGraphExecption? This is for making a difference between general Jedis/Redis exceptions, and JRedisGraph/RedisGraph exceptions.
| } | ||
|
|
||
| @Test | ||
| public void testErrorReporting() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please follow the following example for Juint 4 framework exception assertion:
- first define a rule
@Rule
public ExpectedException exceptionRule = ExpectedException.none();
Then, in the test itself, set the rule expected exception type and message:
@Test
public void testRuntimeException() {
api.query("social", "create ()");
exceptionRule.expect(JedisDataException.class);
exceptionRule.expectMessage("Type mismatch: expected Integer but was String");
api.query("social", "RETURN toUpper(5)");
}
I know it is a bit awkward, once we'll migrate to Juint 5 it will be easier
| return new ResultSetImpl(rawResponse, this, caches.getGraphCache(graphId)); | ||
| } | ||
| catch (JedisDataException j) { | ||
| throw new JRedisGraphCompileTimeError(j); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- please close the connection
conn.close(); - since
JRedisGraphRunTimeErrorextendsJedisDataExceptionthe catch clause will catch it. write additional catch for this type, and just throw. Write it before theJedisDataExceptioncatch, since it inherits from it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DvirDukhan why close?
Codecov Report
@@ Coverage Diff @@
## master #49 +/- ##
==========================================
- Coverage 76.15% 75.86% -0.29%
==========================================
Files 20 22 +2
Lines 478 493 +15
Branches 74 75 +1
==========================================
+ Hits 364 374 +10
- Misses 85 90 +5
Partials 29 29
Continue to review full report at Codecov.
|
| import redis.clients.jedis.exceptions.JedisDataException; | ||
|
|
||
|
|
||
| public class JRedisGraphCompileTimeError extends JedisDataException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DvirDukhan can we had som JDoc here?
| import redis.clients.jedis.exceptions.JedisDataException; | ||
|
|
||
|
|
||
| public class JRedisGraphRunTimeError extends JedisDataException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JDoc?
| return new ResultSetImpl(rawResponse, this, caches.getGraphCache(graphId)); | ||
| } | ||
| catch (JedisDataException j) { | ||
| throw new JRedisGraphCompileTimeError(j); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DvirDukhan why close?
e3ee2ab to
c61a5eb
Compare
This or similar will be necessary following the merge of RedisGraph/RedisGraph#613
Compile-time errors are received by the client
sendQuerylogic asJedisDataExceptions, while for run-time errors, the last top-level member of the response will be aJedisDataException.I believe there may be an issue with premature thread closures here:
https://github.com/RedisGraph/JRedisGraph/blob/master/src/main/java/com/redislabs/redisgraph/impl/api/ContextedRedisGraph.java#L54
I think it would be preferable to not close the connection, at least for
JedisDataExceptionfailures.Let me know your thoughts!