Skip to content

Commit 27a8e96

Browse files
authored
Update backend to report no routing context as DriverError (#915)
1 parent 60d276d commit 27a8e96

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

driver/src/main/java/org/neo4j/driver/internal/DriverFactory.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,16 @@
6161

6262
public class DriverFactory
6363
{
64+
public static final String NO_ROUTING_CONTEXT_ERROR_MESSAGE = "Routing parameters are not supported with scheme 'bolt'. Given URI: ";
65+
6466
public final Driver newInstance( URI uri, AuthToken authToken, RoutingSettings routingSettings,
6567
RetrySettings retrySettings, Config config, SecurityPlan securityPlan )
6668
{
6769
return newInstance( uri, authToken, routingSettings, retrySettings, config, null, securityPlan );
6870
}
6971

70-
public final Driver newInstance ( URI uri, AuthToken authToken, RoutingSettings routingSettings,
71-
RetrySettings retrySettings, Config config, EventLoopGroup eventLoopGroup, SecurityPlan securityPlan )
72+
public final Driver newInstance( URI uri, AuthToken authToken, RoutingSettings routingSettings,
73+
RetrySettings retrySettings, Config config, EventLoopGroup eventLoopGroup, SecurityPlan securityPlan )
7274
{
7375
Bootstrap bootstrap;
7476
boolean ownsEventLoopGroup;
@@ -288,8 +290,7 @@ private static void assertNoRoutingContext( URI uri, RoutingSettings routingSett
288290
RoutingContext routingContext = routingSettings.routingContext();
289291
if ( routingContext.isDefined() )
290292
{
291-
throw new IllegalArgumentException(
292-
"Routing parameters are not supported with scheme 'bolt'. Given URI: '" + uri + "'" );
293+
throw new IllegalArgumentException( NO_ROUTING_CONTEXT_ERROR_MESSAGE + "'" + uri + "'" );
293294
}
294295
}
295296

testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/NewDriver.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import neo4j.org.testkit.backend.messages.responses.BackendError;
2727
import neo4j.org.testkit.backend.messages.responses.DomainNameResolutionRequired;
2828
import neo4j.org.testkit.backend.messages.responses.Driver;
29+
import neo4j.org.testkit.backend.messages.responses.DriverError;
2930
import neo4j.org.testkit.backend.messages.responses.ResolverResolutionRequired;
3031
import neo4j.org.testkit.backend.messages.responses.TestkitResponse;
3132

@@ -87,7 +88,16 @@ public TestkitResponse process( TestkitState testkitState )
8788
}
8889
Optional.ofNullable( data.userAgent ).ifPresent( configBuilder::withUserAgent );
8990
Optional.ofNullable( data.connectionTimeoutMs ).ifPresent( timeout -> configBuilder.withConnectionTimeout( timeout, TimeUnit.MILLISECONDS ) );
90-
testkitState.getDrivers().putIfAbsent( id, driver( URI.create( data.uri ), authToken, configBuilder.build(), domainNameResolver ) );
91+
org.neo4j.driver.Driver driver;
92+
try
93+
{
94+
driver = driver( URI.create( data.uri ), authToken, configBuilder.build(), domainNameResolver );
95+
}
96+
catch ( RuntimeException e )
97+
{
98+
return handleExceptionAsErrorResponse( testkitState, e ).orElseThrow( () -> e );
99+
}
100+
testkitState.getDrivers().putIfAbsent( id, driver );
91101
return Driver.builder().data( Driver.DriverBody.builder().id( id ).build() ).build();
92102
}
93103

@@ -142,6 +152,20 @@ private org.neo4j.driver.Driver driver( URI uri, AuthToken authToken, Config con
142152
.newInstance( uri, authToken, routingSettings, retrySettings, config, securityPlan );
143153
}
144154

155+
private Optional<TestkitResponse> handleExceptionAsErrorResponse( TestkitState testkitState, RuntimeException e )
156+
{
157+
Optional<TestkitResponse> response = Optional.empty();
158+
if ( e instanceof IllegalArgumentException && e.getMessage().startsWith( DriverFactory.NO_ROUTING_CONTEXT_ERROR_MESSAGE ) )
159+
{
160+
String id = testkitState.newId();
161+
String errorType = e.getClass().getName();
162+
response = Optional.of(
163+
DriverError.builder().data( DriverError.DriverErrorBody.builder().id( id ).errorType( errorType ).build() ).build()
164+
);
165+
}
166+
return response;
167+
}
168+
145169
@Setter
146170
@Getter
147171
@NoArgsConstructor

0 commit comments

Comments
 (0)