@Override public String toString() { cause.printStackTrace(); return String.format( "%s[%s, cause=\"%s\"]", getClass().getSimpleName(), status.code(), cause ); }
protected TransactionTerminatedException( Status status, String additionalInfo ) { super( "The transaction has been terminated. Retry your operation in a new transaction, " + "and you should see a successful result. " + status.code().description() + " " + additionalInfo ); this.status = status; }
@Override public String getCode() { return status.code().serialize(); }
@Override public String getTitle() { return status.code().description(); }
public boolean shouldSerializeStackTrace() { switch ( status.code().classification() ) { case ClientError: return false; default: return true; } }
private Neo4jError( Status status, Throwable cause, boolean fatal ) { this( status, status.code().description(), cause, fatal ); }
public AuthenticationException( Status status ) { this( status, status.code().description(), null ); }
@Override public void validateTransaction() throws KernelException { KernelTransaction tx = ctx.currentTransaction; if ( tx != null ) { Optional<Status> statusOpt = tx.getReasonIfTerminated(); if ( statusOpt.isPresent() ) { if ( statusOpt.get().code().classification().rollbackTransaction() ) { ctx.pendingTerminationNotice = statusOpt.get(); reset(); } } } }
public static boolean shouldRollBackOn( Collection<Neo4jError> errors ) { if ( errors.isEmpty() ) { return false; } for ( Neo4jError error : errors ) { if ( error.status().code().classification().rollbackTransaction() ) { return true; } } return false; } }
@Override public void describeTo( Description description ) { description.appendValue( FAILURE ) .appendText( format( " with status code %s", status.code().serialize() ) ); } };
public QueryExecutionException asUserException() { return new QueryExecutionException( getMessage(), this, status().code().serialize() ); } }
private void assertErrors( Map<String, Object> response, Status... expectedErrors ) { @SuppressWarnings( "unchecked" ) Iterator<Map<String, Object>> errors = ((List<Map<String, Object>>) response.get( "errors" )).iterator(); Iterator<Status> expected = iterator( expectedErrors ); while ( expected.hasNext() ) { assertTrue( errors.hasNext() ); assertThat( errors.next().get( "code" ), equalTo( expected.next().code().serialize() ) ); } if ( errors.hasNext() ) { Map<String, Object> error = errors.next(); fail( "Expected no more errors, but got " + error.get( "code" ) + " - '" + error.get( "message" ) + "'." ); } }
/** * Writes logs about database errors. * Short one-line message is written to both user and internal log. * Large message with stacktrace (if available) is written to internal log. * * @param error the error to log. * @see StoreLogService * @see DuplicatingLogProvider */ public void report( Neo4jError error ) { if ( error.status().code().classification() == DatabaseError ) { String message = format( "Client triggered an unexpected error [%s]: %s, reference %s.", error.status().code().serialize(), error.message(), error.reference() ); // Writing to user log gets duplicated to the internal log userLog.error( message ); // If cause/stacktrace is available write it to the internal log if ( error.cause() != null ) { debugLog.error( message, error.cause() ); } } } }
@Test public void eachStatusCodeHasAUniqueCode() { // given Set<Object> codes = new HashSet<>(); // when for ( Status status : Status.Code.all() ) { codes.add( status.code().serialize() ); } // then assertNotEquals( 0, codes.size() ); assertEquals( Status.Code.all().size(), codes.size() ); } }
@Override protected boolean matchesSafely( HTTP.Response response ) { try { Iterator<JsonNode> errors = response.get( "errors" ).iterator(); Iterator<Status> expected = iterator( expectedErrors ); while ( expected.hasNext() ) { assertTrue( errors.hasNext() ); assertThat( errors.next().get( "code" ).asText(), equalTo( expected.next().code().serialize() ) ); } if ( errors.hasNext() ) { JsonNode error = errors.next(); fail( "Expected no more errors, but got " + error.get( "code" ) + " - '" + error.get( "message" ) + "'." ); } return true; } catch ( JsonParseException e ) { return false; } }
@Override protected void serialize( MappingSerializer serializer ) { serializer.putString( "code", error.status().code().serialize() ); serializer.putString( "message", error.getMessage() ); if ( error.shouldSerializeStackTrace() ) { serializer.putString( "stackTrace", error.getStackTraceAsString() ); } }
private void encodeFailure( FailureMessage message, Neo4jPack.Packer packer ) throws IOException { packer.packStructHeader( 1, message.signature() ); packer.packMapHeader( 2 ); packer.pack( "code" ); packer.pack( message.status().code().serialize() ); packer.pack( "message" ); packer.pack( message.message() ); } }
@Override public boolean matches( final Object item ) { final RecordedBoltResponse response = (RecordedBoltResponse) item; return response.message() == FAILURE && response.hasMetadata( "code" ) && response.metadata( "code" ).equals( stringValue( status.code().serialize() ) ); }
@Override public void markFailed( Neo4jError error ) { currentResponse.setResponse( FAILURE ); onMetadata( "code", stringValue( error.status().code().serialize() ) ); onMetadata( "message", stringOrNoValue( error.message() ) ); }
Code statusCode = e.status().code(); if ( statusCode.classification() == Classification.TransientError )