@Override public SyntaxError copy() { return new SyntaxError(getAddress(), getMessage(), this); } }
@Test(groups = "unit") public void should_create_proper_syntax_error() { SyntaxError e = new SyntaxError(address1, "Missing ) at EOF"); assertThat(e.getMessage()).isEqualTo("Missing ) at EOF"); assertThat(e.getAddress()).isEqualTo(address1); assertThat(e.getHost()).isEqualTo(address1.getAddress()); e = (SyntaxError) e.copy(); assertThat(e.getMessage()).isEqualTo("Missing ) at EOF"); assertThat(e.getAddress()).isEqualTo(address1); assertThat(e.getHost()).isEqualTo(address1.getAddress()); }
var test = "true" // or "false" var nameBool = test === "true" || (test === "false" ? false : throw new SyntaxError("non-boolean string value"));
@Override public DriverException copy() { return new SyntaxError(getMessage(), this); } }
/** * Ensures that if an attempt is made to create a {@link Session} via {@link Cluster#connect} with * an invalid keyspace that the returned exception is decorated with an indication to check that * your keyspace name is valid and includes the original {@link SyntaxError}. */ @Test(groups = "short") public void should_give_explicit_error_message_when_keyspace_name_invalid() { try { cluster().connect("%!;"); fail("Expected a SyntaxError"); } catch (SyntaxError e) { assertThat(e.getMessage()) .contains("Error executing \"USE %!;\"") .contains("Check that your keyspace name is valid"); } }
throw new TypeError(); throw new ReferenceError(); throw new SyntaxError(); etc.
/** * Ensures that if an attempt is made to create a {@link Session} via {@link Cluster#connect} with * an invalid keyspace that the returned exception is decorated with an indication to check that * your keyspace name is valid and includes the original {@link SyntaxError}. */ @Test(groups = "short") public void should_give_explicit_error_message_when_keyspace_name_invalid() { try { cluster().connect("%!;"); fail("Expected a SyntaxError"); } catch (SyntaxError e) { assertThat(e.getMessage()) .contains("Error executing \"USE %!;\"") .contains("Check that your keyspace name is valid"); } }
@Override public ListenableFuture<ResultSet> apply(Throwable t) throws Exception { session.closeAsync(); if (t instanceof SyntaxError) { // Give a more explicit message, because it's probably caused by a bad keyspace // name SyntaxError e = (SyntaxError) t; t = new SyntaxError( e.getAddress(), String.format( "Error executing \"%s\" (%s). Check that your keyspace name is valid", useQuery, e.getMessage())); } throw Throwables.propagate(t); } });
@Test(groups = "unit") public void should_create_proper_syntax_error() { SyntaxError e = new SyntaxError(address1, "Missing ) at EOF"); assertThat(e.getMessage()).isEqualTo("Missing ) at EOF"); assertThat(e.getAddress()).isEqualTo(address1); assertThat(e.getHost()).isEqualTo(address1.getAddress()); e = (SyntaxError) e.copy(); assertThat(e.getMessage()).isEqualTo("Missing ) at EOF"); assertThat(e.getAddress()).isEqualTo(address1); assertThat(e.getHost()).isEqualTo(address1.getAddress()); }
return new FunctionExecutionException(host, message); case SYNTAX_ERROR: return new SyntaxError(host, message); case UNAUTHORIZED: return new UnauthorizedException(host, message);
@Override public SyntaxError copy() { return new SyntaxError(getAddress(), getMessage(), this); } }
throw new SyntaxError("No arguments provided."); throw new SyntaxError("Argument is incorrectly formatted."); if (partIndex < 2) { if (part === "" || !/^\d*$/.test(part)) { throw new SyntaxError("Argument is incorrectly formatted."); } else { if (part === "" || !/^\d*\.?\d+$/.test(part)) { throw new SyntaxError("Argument is incorrectly formatted.");
@Override public SyntaxError copy() { return new SyntaxError(getAddress(), getMessage(), this); } }
public DriverException asException(InetSocketAddress host) { switch (code) { case SERVER_ERROR: return new DriverInternalError(String.format("An unexpected error occurred server side on %s: %s", host, message)); case PROTOCOL_ERROR: return new DriverInternalError("An unexpected protocol error occurred. This is a bug in this library, please report: " + message); case BAD_CREDENTIALS: return new AuthenticationException(host, message); case UNAVAILABLE: return ((UnavailableException)infos).copy(); // We copy to have a nice stack trace case OVERLOADED: return new DriverInternalError(String.format("Queried host (%s) was overloaded; this shouldn't happen, another node should have been tried", host)); case IS_BOOTSTRAPPING: return new DriverInternalError(String.format("Queried host (%s) was bootstrapping; this shouldn't happen, another node should have been tried", host)); case TRUNCATE_ERROR: return new TruncateException(message); case WRITE_TIMEOUT: return ((WriteTimeoutException)infos).copy(); case READ_TIMEOUT: return ((ReadTimeoutException)infos).copy(); case SYNTAX_ERROR: return new SyntaxError(message); case UNAUTHORIZED: return new UnauthorizedException(message); case INVALID: return new InvalidQueryException(message); case CONFIG_ERROR: return new InvalidConfigurationInQueryException(message); case ALREADY_EXISTS: return ((AlreadyExistsException)infos).copy(); case UNPREPARED: return new DriverInternalError(String.format("A prepared query was submitted on %s but was not known of that node; this shouldn't happen, the query should have been re-prepared", host)); default: return new DriverInternalError(String.format("Unknown protocol error code %s returned by %s. The error message was: %s", code, host, message)); } }
@Override public SyntaxError copy() { return new SyntaxError(getAddress(), getMessage(), this); } }
return new FunctionExecutionException(host, message); case SYNTAX_ERROR: return new SyntaxError(host, message); case UNAUTHORIZED: return new UnauthorizedException(host, message);
@Override public ListenableFuture<ResultSet> apply(Throwable t) throws Exception { session.closeAsync(); if (t instanceof SyntaxError) { // Give a more explicit message, because it's probably caused by a bad keyspace name SyntaxError e = (SyntaxError) t; t = new SyntaxError(e.getAddress(), String.format("Error executing \"%s\" (%s). Check that your keyspace name is valid", useQuery, e.getMessage())); } throw Throwables.propagate(t); } });
return new FunctionExecutionException(host, message); case SYNTAX_ERROR: return new SyntaxError(host, message); case UNAUTHORIZED: return new UnauthorizedException(host, message);
@Override public ListenableFuture<ResultSet> create(Throwable t) throws Exception { session.closeAsync(); if (t instanceof SyntaxError) { // Give a more explicit message, because it's probably caused by a bad keyspace name SyntaxError e = (SyntaxError) t; t = new SyntaxError(e.getAddress(), String.format("Error executing \"%s\" (%s). Check that your keyspace name is valid", useQuery, e.getMessage())); } throw Throwables.propagate(t); } });
return new FunctionExecutionException(host, message); case SYNTAX_ERROR: return new SyntaxError(host, message); case UNAUTHORIZED: return new UnauthorizedException(host, message);