@Override public SyntaxError copy() { return new SyntaxError(getAddress(), getMessage(), this); } }
@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()); }
/** * 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 DriverException copy() { return new SyntaxError(getMessage(), this); } }
@Override public SyntaxError copy() { return new SyntaxError(getAddress(), getMessage(), this); } }
@Override public SyntaxError copy() { return new SyntaxError(getAddress(), getMessage(), this); } }
@Override public SyntaxError copy() { return new SyntaxError(getAddress(), getMessage(), this); } }
@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); } });
@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); } });
@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); } });
@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()); }
/** * 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"); } }