@Test public void nestedExceptionRetrieval() throws Exception { Exception testException = getException(); Throwable t = getRootException(testException); assertNotNull(t); assertThat(t.getMessage(), is("blah")); assertThat(t.getCause(), nullValue()); t = getRootMuleException(testException); assertThat(t.getMessage(), is("bar")); assertThat(t.getCause(), not(nullValue())); List<Throwable> l = getExceptionsAsList(testException); assertThat(l, hasSize(3)); Map<String, Object> info = getExceptionInfo(testException); assertThat(info.entrySet(), hasSize(2)); assertThat(info, hasEntry("info_1", "Imma in!")); assertThat(info, hasEntry("info_2", "Imma out!")); }
@Test public void getNonMuleExceptionCause() { assertThat(getNonMuleException(new ResolverException(failedToBuildMessage(), null)), nullValue()); assertThat(getNonMuleException(new ResolverException(failedToBuildMessage(), new ConfigurationException(failedToBuildMessage(), null))), nullValue()); assertThat(getNonMuleException(new ResolverException(failedToBuildMessage(), new ConfigurationException(failedToBuildMessage(), new IllegalArgumentException()))), instanceOf(IllegalArgumentException.class)); assertThat(getNonMuleException(new ResolverException(failedToBuildMessage(), new ConfigurationException(failedToBuildMessage(), new IllegalArgumentException(new NullPointerException())))), instanceOf(IllegalArgumentException.class)); assertThat(getNonMuleException(new IllegalArgumentException()), instanceOf(IllegalArgumentException.class)); }
@Test public void filteredStackIncludingNonMuleCode() { int calls = 5; try { generateStackEntries(calls, input -> forAllDo(singleton(null), input1 -> { throw new RuntimeException(new DefaultMuleException(createStaticMessage("foo"))); })); fail("Expected exception"); } catch (Exception e) { assertThat(getExceptionStack(e), StringByLineMatcher.matchesLineByLine("foo \\(org.mule.runtime.api.exception.DefaultMuleException\\)", " " + ExceptionHelperTestCase.class.getName() + ".lambda\\$[^\\(]*\\(ExceptionHelperTestCase.java:[0-9]+\\)", " org.apache.commons.collections.CollectionUtils.forAllDo\\(CollectionUtils.java:[0-9]+\\)", " " + ExceptionHelperTestCase.class.getName() + ".lambda\\$[^\\(]*\\(ExceptionHelperTestCase.java:[0-9]+\\)", " " + ExceptionHelperTestCase.class.getName() + ".generateStackEntries\\(ExceptionHelperTestCase.java:[0-9]+\\)", " \\(" + (calls + 16) + " more...\\)")); // recursive } }
/** * Will shut down the server displaying the cause and time of the shutdown * * @param e the exception that caused the shutdown */ public void shutdown(Throwable e) throws MuleException { I18nMessage msg = fatalErrorWhileRunning(); MuleException muleException = getRootMuleException(e); if (muleException != null) { logger.error(muleException.getDetailedMessage()); } else { logger.error(msg.toString() + " " + e.getMessage(), e); } List<String> msgs = new ArrayList<>(); msgs.add(msg.getMessage()); Throwable root = getRootException(e); msgs.add(root.getMessage() + " (" + root.getClass().getName() + ")"); msgs.add(" "); msgs.add(fatalErrorInShutdown().getMessage()); String shutdownMessage = getBoilerPlate(msgs, '*', 80); logger.error(shutdownMessage); doShutdown(); System.exit(1); }
private Optional<MetadataResult<?>> initializeComponent(Location location) { try { lazyMuleArtifactContext.initializeComponent(location, false); } catch (Exception e) { Throwable rootCause = getRootException(e); MetadataFailure.Builder builder = newFailure(e).withMessage(rootCause.getMessage()); if (rootCause instanceof NoSuchComponentModelException) { builder.withFailureCode(COMPONENT_NOT_FOUND); } return of(failure(builder.onComponent())); } return empty(); }
protected Pair<MuleException, String> resolveExceptionAndMessageToLog(Throwable t) { MuleException muleException = getRootMuleException(t); String logMessage = null; if (muleException != null) { if (!isVerboseExceptions() && t instanceof EventProcessingException && ((EventProcessingException) t).getEvent().getError() .map(e -> CORE_NAMESPACE_NAME.equals(e.getErrorType().getNamespace()) && UNKNOWN_ERROR_IDENTIFIER.equals(e.getErrorType().getIdentifier())) .orElse(false)) { logMessage = ((MuleException) sanitize(muleException)).getVerboseMessage(); } else { logMessage = muleException.getDetailedMessage(); } } return new Pair<>(muleException, logMessage); }
/** * Constructor to create a new builder using the information of an exception for default error parametrization. * * @param e the exception to use from which the error will be created. */ private ErrorBuilder(Throwable e) { if (e instanceof ErrorMessageAwareException) { this.errorMessage = ((ErrorMessageAwareException) e).getErrorMessage(); } if (e instanceof ComposedErrorException) { this.errors = ((ComposedErrorException) e).getErrors(); } this.exception = e; String exceptionDescription = e.getMessage() != null ? e.getMessage() : "unknown description"; this.description = exceptionDescription; this.detailedDescription = exceptionDescription; MuleException muleRoot = getRootMuleException(this.exception); if (muleRoot != null && muleRoot.getMessage() != null) { this.description = muleRoot.getMessage(); } }
private List<Pair<Throwable, ErrorType>> collectCritical(Component obj, MessagingException me, ErrorTypeLocator locator) { List<Pair<Throwable, ErrorType>> errors = new LinkedList<>(); getExceptionsAsList(me).forEach(e -> { ErrorType type = errorTypeFromException(obj, locator, e); if (isCriticalMuleError(type)) { errors.add(new Pair<>(e, type)); } }); return errors; }
/** * Will shut down the server displaying the cause and time of the shutdown * * @param e the exception that caused the shutdown */ public void shutdown(Throwable e) throws MuleException { I18nMessage msg = fatalErrorWhileRunning(); MuleException muleException = getRootMuleException(e); if (muleException != null) { logger.error(muleException.getDetailedMessage()); } else { logger.error(msg.toString() + " " + e.getMessage(), e); } List<String> msgs = new ArrayList<>(); msgs.add(msg.getMessage()); Throwable root = getRootException(e); msgs.add(root.getMessage() + " (" + root.getClass().getName() + ")"); msgs.add(" "); msgs.add(fatalErrorInShutdown().getMessage()); String shutdownMessage = getBoilerPlate(msgs, '*', 80); logger.error(shutdownMessage); doShutdown(); System.exit(1); }
/** * {@inheritDoc} */ @Override public Set<Value> getValues(String parameterName) throws ValueResolvingException { try { return runWithValueProvidersContext(context -> withContextClassLoader(classLoader, () -> valueProviderMediator .getValues(parameterName, getParameterValueResolver(), (CheckedSupplier<Object>) () -> context .getConnection().orElse(null), (CheckedSupplier<Object>) () -> context .getConfig().orElse(null)))); } catch (MuleRuntimeException e) { Throwable rootException = getRootException(e); if (rootException instanceof ValueResolvingException) { throw (ValueResolvingException) rootException; } else { throw new ValueResolvingException("An unknown error occurred trying to resolve values. " + e.getCause().getMessage(), UNKNOWN, e); } } catch (Exception e) { throw new ValueResolvingException("An unknown error occurred trying to resolve values. " + e.getCause().getMessage(), UNKNOWN, e); } }
private List<Pair<Throwable, ErrorType>> collectErrors(Component obj, MessagingException me, ErrorTypeLocator locator) { List<Pair<Throwable, ErrorType>> errors = new LinkedList<>(); getExceptionsAsList(me).forEach(e -> { ErrorType type = errorTypeFromException(obj, locator, e); if (!isUnknownMuleError(type) && !isCriticalMuleError(type)) { errors.add(new Pair<>(e, type)); } }); return errors; }
@Test public void nestedExceptionRetrieval() throws Exception { Exception testException = getException(); Throwable t = getRootException(testException); assertNotNull(t); assertThat(t.getMessage(), is("blah")); assertThat(t.getCause(), nullValue()); t = getRootMuleException(testException); assertThat(t.getMessage(), is("bar")); assertThat(t.getCause(), not(nullValue())); List<Throwable> l = getExceptionsAsList(testException); assertThat(l, hasSize(3)); Map<String, Object> info = getExceptionInfo(testException); assertThat(info.entrySet(), hasSize(2)); assertThat(info, hasEntry("info_1", "Imma in!")); assertThat(info, hasEntry("info_2", "Imma out!")); }
private Optional<ValueResult> initializeComponent(Location location) { Location locationWithOutConnection = locationWithOutConnection(location); try { lazyComponentInitializer.initializeComponent(locationWithOutConnection, false); } catch (Exception e) { Throwable rootException = getRootException(e); if (rootException instanceof NoSuchComponentModelException) { return of(resultFrom(newFailure(e) .withFailureCode(INVALID_LOCATION) .withMessage(format("Unable to resolve values. No component was found in the given location [%s]", location)) .build())); } return of(resultFrom(newFailure(e) .withMessage("Unknown error occurred trying to resolve values. " + e.getMessage()) .withFailureCode(UNKNOWN) .build())); } return empty(); }
@Test public void filteredStackAllMuleCode() { int calls = 5; try { generateStackEntries(calls, input -> { throw new RuntimeException(new DefaultMuleException(createStaticMessage("foo"))); }); } catch (Exception e) { assertThat(getExceptionStack(e), StringByLineMatcher.matchesLineByLine("foo \\(org.mule.runtime.api.exception.DefaultMuleException\\)", " " + ExceptionHelperTestCase.class.getName() + ".lambda\\$[^\\(]*\\(ExceptionHelperTestCase.java:[0-9]+\\)", " " + ExceptionHelperTestCase.class.getName() + ".generateStackEntries\\(ExceptionHelperTestCase.java:[0-9]+\\)", " " + ExceptionHelperTestCase.class.getName() + ".generateStackEntries\\(ExceptionHelperTestCase.java:[0-9]+\\)", " \\(" + (calls + 15) + " more...\\)")); // recursive } }
private Optional<MetadataResult<?>> initializeComponent(Location location) { try { lazyMuleArtifactContext.initializeComponent(location, false); } catch (Exception e) { Throwable rootCause = getRootException(e); MetadataFailure.Builder builder = newFailure(e).withMessage(rootCause.getMessage()); if (rootCause instanceof NoSuchComponentModelException) { builder.withFailureCode(COMPONENT_NOT_FOUND); } return of(failure(builder.onComponent())); } return empty(); }
@Test public void getNonMuleExceptionCause() { assertThat(getNonMuleException(new ResolverException(failedToBuildMessage(), null)), nullValue()); assertThat(getNonMuleException(new ResolverException(failedToBuildMessage(), new ConfigurationException(failedToBuildMessage(), null))), nullValue()); assertThat(getNonMuleException(new ResolverException(failedToBuildMessage(), new ConfigurationException(failedToBuildMessage(), new IllegalArgumentException()))), instanceOf(IllegalArgumentException.class)); assertThat(getNonMuleException(new ResolverException(failedToBuildMessage(), new ConfigurationException(failedToBuildMessage(), new IllegalArgumentException(new NullPointerException())))), instanceOf(IllegalArgumentException.class)); assertThat(getNonMuleException(new IllegalArgumentException()), instanceOf(IllegalArgumentException.class)); }
@Test public void filteredStackIncludingMixedNonMuleCode() { int calls = 5; try { generateStackEntries(calls, input -> { Comparable exceptionComparable = o -> { throw new RuntimeException(new DefaultMuleException(createStaticMessage("foo"))); }; sort(asList(exceptionComparable, exceptionComparable), ComparableComparator.getInstance()); }); fail("Expected exception"); } catch (Exception e) { assertThat(getExceptionStack(e), StringByLineMatcher.matchesLineByLine("foo \\(org.mule.runtime.api.exception.DefaultMuleException\\)", " " + ExceptionHelperTestCase.class.getName() + ".lambda\\$[^\\(]*\\(ExceptionHelperTestCase.java:[0-9]+\\)", " org.apache.commons.collections.comparators.ComparableComparator.compare\\(ComparableComparator.java:[0-9]+\\)", " java.util.*", // Collections.sort " java.util.*", // Collections.sort " java.util.*", // Collections.sort " java.util.*", // Collections.sort " java.util.*", // Collections.sort " " + ExceptionHelperTestCase.class.getName() + ".lambda\\$[^\\(]*\\(ExceptionHelperTestCase.java:[0-9]+\\)", " " + ExceptionHelperTestCase.class.getName() + ".generateStackEntries\\(ExceptionHelperTestCase.java:[0-9]+\\)", " \\(" + (calls + 16) + " more...\\)")); // recursive } }
/** * {@inheritDoc} */ @Override public Set<Value> getValues(String parameterName) throws ValueResolvingException { try { return runWithValueProvidersContext(context -> withContextClassLoader(getClassLoader(this.extensionModel), () -> valueProviderMediator .getValues(parameterName, getParameterValueResolver(), (CheckedSupplier<Object>) () -> context .getConnection().orElse(null), (CheckedSupplier<Object>) () -> context .getConfig().orElse(null)))); } catch (MuleRuntimeException e) { Throwable rootException = getRootException(e); if (rootException instanceof ValueResolvingException) { throw (ValueResolvingException) rootException; } else { throw new ValueResolvingException("An unknown error occurred trying to resolve values. " + e.getCause().getMessage(), UNKNOWN, e); } } catch (Exception e) { throw new ValueResolvingException("An unknown error occurred trying to resolve values. " + e.getCause().getMessage(), UNKNOWN, e); } }
@Test public void filteredStackAllMuleCode() { int calls = 5; try { generateStackEntries(calls, input -> { throw new RuntimeException(new DefaultMuleException(createStaticMessage("foo"))); }); } catch (Exception e) { assertThat(getExceptionStack(e), StringByLineMatcher.matchesLineByLine("foo \\(org.mule.runtime.api.exception.DefaultMuleException\\)", " " + ExceptionHelperTestCase.class.getName() + ".lambda\\$[^\\(]*\\(ExceptionHelperTestCase.java:[0-9]+\\)", " " + ExceptionHelperTestCase.class.getName() + ".generateStackEntries\\(ExceptionHelperTestCase.java:[0-9]+\\)", " " + ExceptionHelperTestCase.class.getName() + ".generateStackEntries\\(ExceptionHelperTestCase.java:[0-9]+\\)", " \\(" + (calls + 15) + " more...\\)")); // recursive } }