Skip to content

Commit ed0c37c

Browse files
jeffreylovitzDvirDukhan
andauthored
Don't use separate error classes for run-time and compile-time exceptions (#108)
Co-authored-by: DvirDukhan <[email protected]>
1 parent 541eed4 commit ed0c37c

File tree

6 files changed

+39
-61
lines changed

6 files changed

+39
-61
lines changed

src/main/java/com/redislabs/redisgraph/exceptions/JRedisGraphCompileTimeException.java

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.redislabs.redisgraph.exceptions;
2+
3+
import redis.clients.jedis.exceptions.JedisDataException;
4+
5+
/**
6+
* RedisGraph query evaluation exception. An instance of JRedisGraphException is thrown when RedisGraph
7+
* encounters an error during query evaluation.
8+
*/
9+
public class JRedisGraphException extends JedisDataException {
10+
public JRedisGraphException(String message) {
11+
super(message);
12+
}
13+
14+
public JRedisGraphException(Throwable cause) {
15+
super(cause);
16+
}
17+
18+
public JRedisGraphException(String message, Throwable cause) {
19+
super(message, cause);
20+
}
21+
}

src/main/java/com/redislabs/redisgraph/exceptions/JRedisGraphRunTimeException.java

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/main/java/com/redislabs/redisgraph/impl/api/ContextedRedisGraph.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
import com.redislabs.redisgraph.RedisGraphContext;
44
import com.redislabs.redisgraph.ResultSet;
5-
import com.redislabs.redisgraph.exceptions.JRedisGraphCompileTimeException;
6-
import com.redislabs.redisgraph.exceptions.JRedisGraphRunTimeException;
5+
import com.redislabs.redisgraph.exceptions.JRedisGraphException;
76
import com.redislabs.redisgraph.impl.Utils;
87
import com.redislabs.redisgraph.impl.graph_cache.RedisGraphCaches;
98
import com.redislabs.redisgraph.impl.resultset.ResultSetImpl;
@@ -52,11 +51,11 @@ protected ResultSet sendQuery(String graphId, String preparedQuery) {
5251
List<Object> rawResponse = (List<Object>) conn.sendCommand(RedisGraphCommand.QUERY, graphId, preparedQuery, Utils.COMPACT_STRING);
5352
return new ResultSetImpl(rawResponse, this, caches.getGraphCache(graphId));
5453
}
55-
catch (JRedisGraphRunTimeException rt) {
54+
catch (JRedisGraphException rt) {
5655
throw rt;
5756
}
5857
catch (JedisDataException j) {
59-
throw new JRedisGraphCompileTimeException(j);
58+
throw new JRedisGraphException(j);
6059
}
6160
}
6261

@@ -75,11 +74,11 @@ protected ResultSet sendQuery(String graphId, String preparedQuery, long timeout
7574
graphId, preparedQuery, Utils.COMPACT_STRING, Utils.TIMEOUT_STRING, Long.toString(timeout));
7675
return new ResultSetImpl(rawResponse, this, caches.getGraphCache(graphId));
7776
}
78-
catch (JRedisGraphRunTimeException rt) {
77+
catch (JRedisGraphException rt) {
7978
throw rt;
8079
}
8180
catch (JedisDataException j) {
82-
throw new JRedisGraphCompileTimeException(j);
81+
throw new JRedisGraphException(j);
8382
}
8483
}
8584

src/main/java/com/redislabs/redisgraph/impl/resultset/ResultSetImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import com.redislabs.redisgraph.RedisGraph;
66
import com.redislabs.redisgraph.ResultSet;
77
import com.redislabs.redisgraph.Statistics;
8-
import com.redislabs.redisgraph.exceptions.JRedisGraphRunTimeException;
8+
import com.redislabs.redisgraph.exceptions.JRedisGraphException;
99
import com.redislabs.redisgraph.graph_entities.*;
1010
import com.redislabs.redisgraph.impl.graph_cache.GraphCache;
1111
import redis.clients.jedis.util.SafeEncoder;
@@ -37,7 +37,7 @@ public ResultSetImpl(List<Object> rawResponse, RedisGraph redisGraph, GraphCache
3737
// If a run-time error occurred, the last member of the rawResponse will be a JedisDataException.
3838
if (rawResponse.get(rawResponse.size() - 1) instanceof JedisDataException) {
3939

40-
throw new JRedisGraphRunTimeException((Throwable) rawResponse.get(rawResponse.size() - 1));
40+
throw new JRedisGraphException((Throwable) rawResponse.get(rawResponse.size() - 1));
4141
}
4242

4343
if (rawResponse.size() != 3) {

src/test/java/com/redislabs/redisgraph/exceptions/JRedisGraphErrorTest.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public void deleteGraph() {
3434

3535
@Test
3636
public void testSyntaxErrorReporting() {
37-
exceptionRule.expect(JRedisGraphCompileTimeException.class);
37+
exceptionRule.expect(JRedisGraphException.class);
3838
exceptionRule.expectMessage("Type mismatch: expected String but was Integer");
3939

4040
// Issue a query that causes a compile-time error
@@ -44,7 +44,7 @@ public void testSyntaxErrorReporting() {
4444

4545
@Test
4646
public void testRuntimeErrorReporting() {
47-
exceptionRule.expect(JRedisGraphRunTimeException.class);
47+
exceptionRule.expect(JRedisGraphException.class);
4848
exceptionRule.expectMessage("Type mismatch: expected String but was Integer");
4949

5050
// Issue a query that causes a run-time error
@@ -59,7 +59,7 @@ public void testExceptionFlow() {
5959
api.query("social", "RETURN toUpper(5)");
6060
}
6161
catch (Exception e) {
62-
Assert.assertEquals(JRedisGraphCompileTimeException.class, e.getClass());
62+
Assert.assertEquals(JRedisGraphException.class, e.getClass());
6363
Assert.assertTrue( e.getMessage().contains("Type mismatch: expected String but was Integer"));
6464
}
6565

@@ -70,7 +70,7 @@ public void testExceptionFlow() {
7070
api.query("social", "MATCH (p:person) RETURN toUpper(p.mixed_prop)");
7171
}
7272
catch (Exception e) {
73-
Assert.assertEquals(JRedisGraphRunTimeException.class, e.getClass());
73+
Assert.assertEquals(JRedisGraphException.class, e.getClass());
7474
Assert.assertTrue( e.getMessage().contains("Type mismatch: expected String but was Integer"));
7575
}
7676

@@ -79,7 +79,7 @@ public void testExceptionFlow() {
7979

8080
@Test
8181
public void testContextSyntaxErrorReporting() {
82-
exceptionRule.expect(JRedisGraphCompileTimeException.class);
82+
exceptionRule.expect(JRedisGraphException.class);
8383
exceptionRule.expectMessage("Type mismatch: expected String but was Integer");
8484
RedisGraphContext c = api.getContext();
8585

@@ -90,21 +90,21 @@ public void testContextSyntaxErrorReporting() {
9090

9191
@Test
9292
public void testMissingParametersSyntaxErrorReporting(){
93-
exceptionRule.expect(JRedisGraphRunTimeException.class);
93+
exceptionRule.expect(JRedisGraphException.class);
9494
exceptionRule.expectMessage("Missing parameters");
9595
api.query("social","RETURN $param");
9696
}
9797

9898
@Test
9999
public void testMissingParametersSyntaxErrorReporting2(){
100-
exceptionRule.expect(JRedisGraphRunTimeException.class);
100+
exceptionRule.expect(JRedisGraphException.class);
101101
exceptionRule.expectMessage("Missing parameters");
102102
api.query("social","RETURN $param", new HashMap<>());
103103
}
104104

105105
@Test
106106
public void testContextRuntimeErrorReporting() {
107-
exceptionRule.expect(JRedisGraphRunTimeException.class);
107+
exceptionRule.expect(JRedisGraphException.class);
108108
exceptionRule.expectMessage("Type mismatch: expected String but was Integer");
109109

110110
RedisGraphContext c = api.getContext();
@@ -122,7 +122,7 @@ public void testContextExceptionFlow() {
122122
c.query("social", "RETURN toUpper(5)");
123123
}
124124
catch (Exception e) {
125-
Assert.assertEquals(JRedisGraphCompileTimeException.class, e.getClass());
125+
Assert.assertEquals(JRedisGraphException.class, e.getClass());
126126
Assert.assertTrue( e.getMessage().contains("Type mismatch: expected String but was Integer"));
127127
}
128128

@@ -133,15 +133,15 @@ public void testContextExceptionFlow() {
133133
c.query("social", "MATCH (p:person) RETURN toUpper(p.mixed_prop)");
134134
}
135135
catch (Exception e) {
136-
Assert.assertEquals(JRedisGraphRunTimeException.class, e.getClass());
136+
Assert.assertEquals(JRedisGraphException.class, e.getClass());
137137
Assert.assertTrue( e.getMessage().contains("Type mismatch: expected String but was Integer"));
138138
}
139139

140140
}
141141

142142
@Test
143143
public void timeoutExcpetion() {
144-
exceptionRule.expect(JRedisGraphRunTimeException.class);
144+
exceptionRule.expect(JRedisGraphException.class);
145145
exceptionRule.expectMessage("Query timed out");
146146

147147
api.query("social", "UNWIND range(0,100000) AS x WITH x AS x WHERE x = 10000 RETURN x", 1L);

0 commit comments

Comments
 (0)