@SuppressWarnings( "rawtypes" ) public static boolean contains( final Throwable cause, final String containsMessage, final Class... anyOfTheseClasses ) { final Predicate<Throwable> anyOfClasses = Predicates.instanceOfAny( anyOfTheseClasses ); return contains( cause, item -> item.getMessage() != null && item.getMessage().contains( containsMessage ) && anyOfClasses.test( item ) ); }
private static IndexEntryConflictException buildCauseChain( Set<IndexEntryConflictException> conflicts ) { IndexEntryConflictException chainedConflicts = null; for ( IndexEntryConflictException conflict : conflicts ) { chainedConflicts = Exceptions.chain( chainedConflicts, conflict ); } return chainedConflicts; }
@Override public String asString() { return Exceptions.stringify( failure ); }
private RuntimeException exitConstructor( Throwable throwable ) { try { close(); } catch ( IOException e ) { throwable = Exceptions.chain( new UncheckedIOException( e ), throwable ); } appendTreeInformation( throwable ); Exceptions.throwIfUnchecked( throwable ); return new RuntimeException( throwable ); }
static void assertExceptionContains( Exception e, String message, Class<? extends Exception> type ) throws Exception { if ( !contains( e, message, type ) ) { // Rethrow the exception since we'd like to see what it was instead throw withMessage( e, format( "Expected exception to contain cause '%s', %s. but was %s", message, type, e ) ); } }
public static ServerStartupException translateToServerStartupError( Throwable cause ) { Throwable rootCause = Exceptions.rootCause( cause ); if ( rootCause instanceof UpgradeNotAllowedException ) { return new UpgradeDisallowedStartupException( (UpgradeNotAllowedException) rootCause ); } return new ServerStartupException( format( "Starting Neo4j failed: %s", cause.getMessage() ), cause ); } }
public static void awaitTermination(Collection<Future<?>> futures) { boolean done = false; Throwable error = null; try { for (Future<?> future : futures) { try { future.get(); } catch (ExecutionException ee) { final Throwable cause = ee.getCause(); if (error != cause) { error = Exceptions.chain(error, cause); } } catch (CancellationException ignore) { } } done = true; } catch (InterruptedException e) { error = Exceptions.chain(e, error); } finally { if (!done) { for (final Future<?> future : futures) { future.cancel(true); } } } if (error != null) { throw Exceptions.launderedException(error); } }
@Override public void assertHealthy() { if ( panic != null ) { throwIfUnchecked( panic ); throw new RuntimeException( panic ); } }
private void enhanceFailureWithSeed( Throwable t ) { Exceptions.withMessage( t, t.getMessage() + ": random seed used:" + seed + "L" ); } };
else if ( Exceptions.contains( e, IllegalMultilineFieldException.class ) ) "true.", e, stackTrace, err ); else if ( Exceptions.contains( e, InputException.class ) ) throwIfUnchecked( e ); return new RuntimeException( e ); // throw in order to have process exit with !0
/** * @deprecated See {@link #launderedException(Class, String, Throwable)}. */ @Deprecated public static RuntimeException launderedException( String messageForUnexpected, Throwable exception ) { return launderedException( RuntimeException.class, messageForUnexpected, exception ); }
e = withMessage( e, e.getMessage() + ". At position " + position + " and entry version " + version ); continue; throwIfInstanceOf( e, UnsupportedLogVersionException.class ); throw new IOException( e );
@Test void canPeelExceptions() { // given Throwable expected; Throwable exception = new LevelOneException( "", new LevelTwoException( "", new LevelThreeException( "", expected = new LevelThreeException( "include", new LevelFourException( "" ) ) ) ) ); // when Throwable peeled = Exceptions.peel( exception, item -> !(item instanceof LevelThreeException) || !item.getMessage().contains( "include" ) ); // then assertEquals( expected, peeled ); }
private void verifyAcquisitionFailure( Future<Boolean> lockAcquisition ) throws InterruptedException { try { lockAcquisition.get(); fail("Lock acquisition should fail."); } catch ( ExecutionException e ) { assertThat( Exceptions.rootCause( e ), instanceOf( LockAcquisitionTimeoutException.class ) ); } } }
public static void awaitTermination(Collection<Future<?>> futures) { boolean done = false; Throwable error = null; try { for (Future<?> future : futures) { try { future.get(); } catch (ExecutionException ee) { final Throwable cause = ee.getCause(); if (error != cause) { error = Exceptions.chain(error, cause); } } catch (CancellationException ignore) { } } done = true; } catch (InterruptedException e) { error = Exceptions.chain(e, error); } finally { if (!done) { for (final Future<?> future : futures) { future.cancel(true); } } } if (error != null) { throw Exceptions.launderedException(error); } }
/** * Halts this flusher, making it stop flushing. The current call to {@link PageCache#flushAndForce()} * will complete before exiting this method call. If there was an error in the thread doing the flushes * that exception will be thrown from this method as a {@link RuntimeException}. */ void halt() { halted = true; halt.await(); if ( error != null ) { throwIfUnchecked( error ); throw new RuntimeException( error ); } } }
@Override public IndexSample sampleIndex() throws IndexNotFoundKernelException { List<IndexSample> samples = new ArrayList<>(); Exception exception = null; for ( IndexSampler sampler : samplers ) { try { samples.add( sampler.sampleIndex() ); } catch ( IndexNotFoundKernelException | RuntimeException e ) { exception = Exceptions.chain( exception, e ); } } if ( exception != null ) { Exceptions.throwIfUnchecked( exception ); throw (IndexNotFoundKernelException)exception; } return combineSamples( samples ); }
private <E extends Throwable> void appendTreeInformation( E e ) { Exceptions.withMessage( e, e.getMessage() + " | " + toString() ); }
/** * @deprecated See {@link #launderedException(Class, String, Throwable)}. */ @Deprecated public static RuntimeException launderedException( Throwable exception ) { return launderedException( RuntimeException.class, UNEXPECTED_MESSAGE, exception ); }
@Test void canPeelUsingConveniencePredicate() { // given Throwable expected; Throwable exception = new ARuntimeException( new AnotherRuntimeException( new LevelFourException( "", expected = new LevelThreeException( "", new LevelFourException( "" ) ) ) ) ); // when Throwable peeled = Exceptions.peel( exception, Predicates.instanceOfAny( RuntimeException.class, LevelFourException.class ) ); // then assertEquals( expected, peeled ); }