Skip to content

Conversation

@jeffreylovitz
Copy link
Contributor

This or similar will be necessary following the merge of RedisGraph/RedisGraph#613

Compile-time errors are received by the client sendQuery logic as JedisDataExceptions, while for run-time errors, the last top-level member of the response will be a JedisDataException.

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 JedisDataException failures.
Let me know your thoughts!

Copy link
Contributor

@DvirDukhan DvirDukhan left a 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) {
Copy link
Contributor

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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

few questions:

  1. Isn't a JedisDataException thrown, and not returned?
  2. 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() {
Copy link
Contributor

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:

  1. 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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. please close the connection conn.close();
  2. since JRedisGraphRunTimeError extends JedisDataException the catch clause will catch it. write additional catch for this type, and just throw. Write it before the JedisDataException catch, since it inherits from it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DvirDukhan why close?

@codecov
Copy link

codecov bot commented Sep 12, 2019

Codecov Report

Merging #49 into master will decrease coverage by 0.28%.
The diff coverage is 55.55%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
...slabs/redisgraph/impl/resultset/ResultSetImpl.java 81.9% <100%> (+0.35%) ⬆️
...slabs/redisgraph/impl/api/ContextedRedisGraph.java 73.52% <100%> (+9.89%) ⬆️
...ph/exceptions/JRedisGraphCompileTimeException.java 33.33% <33.33%> (ø)
...sgraph/exceptions/JRedisGraphRunTimeException.java 33.33% <33.33%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 42f4766...c61a5eb. Read the comment docs.

import redis.clients.jedis.exceptions.JedisDataException;


public class JRedisGraphCompileTimeError extends JedisDataException {
Copy link
Contributor

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 {
Copy link
Contributor

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DvirDukhan why close?

@DvirDukhan DvirDukhan force-pushed the runtime-error-handling branch from e3ee2ab to c61a5eb Compare September 12, 2019 19:25
@DvirDukhan DvirDukhan merged commit 9fda93e into master Sep 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants