Search in sources :

Example 1 with Error

use of org.mule.runtime.api.message.Error in project mule by mulesoft.

the class DataWeaveExpressionLanguageAdaptorTestCase method fullErrorBinding.

@Test
public void fullErrorBinding() throws Exception {
    String description = "An error occurred";
    String detailedDescription = "A division by zero has collapsed our systems.";
    String exceptionMessage = "dividend cannot be zero";
    String errorId = "WEAVE_TEST";
    ErrorType errorType = mock(ErrorType.class);
    when(errorType.getIdentifier()).thenReturn(errorId);
    Error error = ErrorBuilder.builder().description(description).detailedDescription(detailedDescription).exception(new IllegalArgumentException(exceptionMessage)).errorType(errorType).build();
    Optional opt = Optional.of(error);
    CoreEvent event = getEventWithError(opt);
    doReturn(testEvent().getMessage()).when(event).getMessage();
    String expression = "'$(error.description) $(error.detailedDescription) $(error.cause.message) $(error.errorType.identifier)'";
    TypedValue result = expressionLanguage.evaluate(expression, event, BindingContext.builder().build());
    assertThat(result.getValue(), is(format("%s %s %s %s", description, detailedDescription, exceptionMessage, errorId)));
}
Also used : ErrorType(org.mule.runtime.api.message.ErrorType) Optional(java.util.Optional) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Error(org.mule.runtime.api.message.Error) Matchers.containsString(org.hamcrest.Matchers.containsString) TypedValue(org.mule.runtime.api.metadata.TypedValue) Test(org.junit.Test)

Example 2 with Error

use of org.mule.runtime.api.message.Error in project mule by mulesoft.

the class MessagingExceptionResolverTestCase method resolveWithAnEventThatCarriesError.

@Test
public void resolveWithAnEventThatCarriesError() {
    Optional<Error> surfaceError = mockError(TRANSFORMER, null);
    when(event.getError()).thenReturn(surfaceError);
    MessagingException me = newMessagingException(new Exception(), event, processor);
    MessagingException resolved = resolver.resolve(me, context);
    assertExceptionErrorType(resolved, TRANSFORMER);
    assertExceptionMessage(resolved.getMessage(), ERROR_MESSAGE);
}
Also used : MessagingException(org.mule.runtime.core.internal.exception.MessagingException) Error(org.mule.runtime.api.message.Error) MuleFatalException(org.mule.runtime.api.exception.MuleFatalException) MuleException(org.mule.runtime.api.exception.MuleException) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) TransformerException(org.mule.runtime.core.api.transformer.TransformerException) ConnectionException(org.mule.runtime.api.connection.ConnectionException) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 3 with Error

use of org.mule.runtime.api.message.Error in project mule by mulesoft.

the class MessagingExceptionResolverTestCase method mockError.

private Optional<Error> mockError(ErrorType errorType, Throwable cause) {
    Error error = mock(Error.class);
    when(error.getErrorType()).thenReturn(errorType);
    when(error.getCause()).thenReturn(cause);
    return Optional.of(error);
}
Also used : Error(org.mule.runtime.api.message.Error)

Example 4 with Error

use of org.mule.runtime.api.message.Error in project mule by mulesoft.

the class MessagingExceptionResolverTestCase method resolveWithParentInChain.

@Test
public void resolveWithParentInChain() {
    ErrorType withParent = ErrorTypeBuilder.builder().parentErrorType(CONNECTION).identifier("CONNECT").namespace("TEST").build();
    Optional<Error> surfaceError = mockError(withParent, new Exception());
    when(event.getError()).thenReturn(surfaceError);
    Exception cause = new ConnectionException("Some Connection Error", new Exception());
    MessagingException me = newMessagingException(cause, event, processor);
    MessagingException resolved = resolver.resolve(me, context);
    assertExceptionErrorType(resolved, withParent);
    assertExceptionMessage(resolved.getMessage(), ERROR_MESSAGE);
}
Also used : ErrorType(org.mule.runtime.api.message.ErrorType) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) Error(org.mule.runtime.api.message.Error) MuleFatalException(org.mule.runtime.api.exception.MuleFatalException) MuleException(org.mule.runtime.api.exception.MuleException) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) TransformerException(org.mule.runtime.core.api.transformer.TransformerException) ConnectionException(org.mule.runtime.api.connection.ConnectionException) ConnectionException(org.mule.runtime.api.connection.ConnectionException) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 5 with Error

use of org.mule.runtime.api.message.Error in project mule by mulesoft.

the class InternalExceptionUtils method getErrorFromFailingProcessor.

/**
 * Determine the {@link ErrorType} of a given exception thrown by a given message processor.
 *
 * @param processor the component that threw the exception (processor or source).
 * @param cause the exception thrown.
 * @param locator the {@link ErrorTypeLocator}.
 * @return the resolved {@link ErrorType}
 */
public static Error getErrorFromFailingProcessor(CoreEvent currentEvent, Component processor, Throwable cause, ErrorTypeLocator locator) {
    ErrorType currentError = currentEvent != null ? currentEvent.getError().map(Error::getErrorType).orElse(null) : null;
    ErrorType foundErrorType = locator.lookupErrorType(cause);
    ErrorType resultError = isUnknownMuleError(foundErrorType) ? currentError : foundErrorType;
    ErrorType errorType = getComponentIdentifier(processor).map(ci -> locator.lookupComponentErrorType(ci, cause)).orElse(locator.lookupErrorType(cause));
    return ErrorBuilder.builder(cause).errorType(getErrorMappings(processor).stream().filter(m -> m.match(resultError == null || isUnknownMuleError(resultError) ? errorType : currentError)).findFirst().map(ErrorMapping::getTarget).orElse(errorType)).build();
}
Also used : ErrorMapping(org.mule.runtime.core.internal.exception.ErrorMapping) Collections.emptyList(java.util.Collections.emptyList) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) ExceptionUtils.getComponentIdentifier(org.mule.runtime.core.api.util.ExceptionUtils.getComponentIdentifier) ErrorBuilder(org.mule.runtime.core.internal.message.ErrorBuilder) List(java.util.List) Component(org.mule.runtime.api.component.Component) ErrorType(org.mule.runtime.api.message.ErrorType) ExceptionUtils.isUnknownMuleError(org.mule.runtime.core.api.util.ExceptionUtils.isUnknownMuleError) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) ANNOTATION_ERROR_MAPPINGS(org.mule.runtime.core.internal.exception.ErrorMapping.ANNOTATION_ERROR_MAPPINGS) Error(org.mule.runtime.api.message.Error) ErrorTypeLocator(org.mule.runtime.core.privileged.exception.ErrorTypeLocator) ErrorType(org.mule.runtime.api.message.ErrorType) ExceptionUtils.isUnknownMuleError(org.mule.runtime.core.api.util.ExceptionUtils.isUnknownMuleError) Error(org.mule.runtime.api.message.Error)

Aggregations

Error (org.mule.runtime.api.message.Error)30 Test (org.junit.Test)18 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)11 SmallTest (org.mule.tck.size.SmallTest)11 MuleException (org.mule.runtime.api.exception.MuleException)10 MessagingException (org.mule.runtime.core.internal.exception.MessagingException)9 ErrorType (org.mule.runtime.api.message.ErrorType)7 Optional (java.util.Optional)6 Matchers.containsString (org.hamcrest.Matchers.containsString)5 ConnectionException (org.mule.runtime.api.connection.ConnectionException)5 MuleFatalException (org.mule.runtime.api.exception.MuleFatalException)5 TransformerException (org.mule.runtime.core.api.transformer.TransformerException)5 Component (org.mule.runtime.api.component.Component)4 TypedValue (org.mule.runtime.api.metadata.TypedValue)4 Message (org.mule.runtime.api.message.Message)3 ExceptionUtils.isUnknownMuleError (org.mule.runtime.core.api.util.ExceptionUtils.isUnknownMuleError)3 ErrorMapping (org.mule.runtime.core.internal.exception.ErrorMapping)3 List (java.util.List)2 DefaultMuleException (org.mule.runtime.api.exception.DefaultMuleException)2 I18nMessageFactory.createStaticMessage (org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage)2