Search in sources :

Example 16 with ErrorType

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

the class DefaultErrorTypeRepository method addInternalErrorType.

/**
 * {@inheritDoc}
 */
@Override
public ErrorType addInternalErrorType(ComponentIdentifier errorTypeIdentifier, ErrorType parentErrorType) {
    ErrorType errorType = buildErrorType(errorTypeIdentifier, parentErrorType);
    internalErrorTypes.put(errorTypeIdentifier, errorType);
    return errorType;
}
Also used : ErrorType(org.mule.runtime.api.message.ErrorType)

Example 17 with ErrorType

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

the class BeanDefinitionFactory method resolveErrorType.

private ErrorType resolveErrorType(String representation) {
    int separator = representation.indexOf(":");
    String namespace;
    String identifier;
    if (separator > 0) {
        namespace = representation.substring(0, separator).toUpperCase();
        identifier = representation.substring(separator + 1).toUpperCase();
    } else {
        namespace = CORE_ERROR_NS;
        identifier = representation.toUpperCase();
    }
    ComponentIdentifier errorIdentifier = ComponentIdentifier.builder().namespace(namespace).name(identifier).build();
    if (CORE_ERROR_NS.equals(namespace)) {
        return errorTypeRepository.lookupErrorType(errorIdentifier).orElseThrow(() -> new MuleRuntimeException(createStaticMessage(format("There's no MULE error named '%s'.", identifier))));
    } else if (errorTypeRepository.getErrorNamespaces().contains(namespace) && !syntheticErrorNamespaces.contains(namespace)) {
        throw new MuleRuntimeException(createStaticMessage(format("Cannot use error type '%s:%s': namespace already exists.", namespace, identifier)));
    } else if (syntheticErrorNamespaces.contains(namespace)) {
        Optional<ErrorType> optionalErrorType = errorTypeRepository.lookupErrorType(errorIdentifier);
        if (optionalErrorType.isPresent()) {
            return optionalErrorType.get();
        }
    } else {
        syntheticErrorNamespaces.add(namespace);
    }
    return errorTypeRepository.addErrorType(errorIdentifier, errorTypeRepository.getAnyErrorType());
}
Also used : ErrorType(org.mule.runtime.api.message.ErrorType) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) ComponentIdentifier(org.mule.runtime.api.component.ComponentIdentifier)

Example 18 with ErrorType

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

the class ThrowProcessor method process.

@Override
public CoreEvent process(CoreEvent event) throws MuleException {
    if (count == -1 || count-- > 0) {
        try {
            Throwable instantiatedException = exception.newInstance();
            if (error != null) {
                ErrorTypeRepository errorTypeRepository = muleContext.getErrorTypeRepository();
                ErrorType errorType = errorTypeRepository.lookupErrorType(buildFromStringRepresentation(error)).orElseThrow(() -> new DefaultMuleException(format("Could not find error: '%s'", error)));
                throw new TypedException(instantiatedException, errorType);
            } else {
                checkArgument(instantiatedException instanceof TypedException, EXCEPTION_ERROR);
                throw (TypedException) instantiatedException;
            }
        } catch (InstantiationException | IllegalAccessException e) {
            throw new DefaultMuleException(format("Failed to instantiate exception class '%s'", exception.getSimpleName()));
        }
    } else {
        return event;
    }
}
Also used : ErrorTypeRepository(org.mule.runtime.api.exception.ErrorTypeRepository) DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) ErrorType(org.mule.runtime.api.message.ErrorType) TypedException(org.mule.runtime.api.exception.TypedException)

Example 19 with ErrorType

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

the class DataWeaveExpressionLanguageAdaptorTestCase method childErrorsErrorBinding.

@Test
public void childErrorsErrorBinding() throws Exception {
    String childErrorMessage = "error";
    String otherChildErrorMessage = "oops";
    ErrorType errorType = mock(ErrorType.class);
    Error error = mock(Error.class);
    when(error.getChildErrors()).thenReturn(asList(ErrorBuilder.builder(new IOException(childErrorMessage)).errorType(errorType).build(), ErrorBuilder.builder(new DefaultMuleException(otherChildErrorMessage)).errorType(errorType).build()));
    Optional opt = Optional.of(error);
    CoreEvent event = getEventWithError(opt);
    doReturn(testEvent().getMessage()).when(event).getMessage();
    String expression = "error.childErrors reduce ((child, acc = '') -> acc ++ child.cause.message)";
    TypedValue result = expressionLanguage.evaluate(expression, event, BindingContext.builder().build());
    assertThat(result.getValue(), is(format("%s%s", childErrorMessage, otherChildErrorMessage)));
}
Also used : DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) 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) IOException(java.io.IOException) TypedValue(org.mule.runtime.api.metadata.TypedValue) Test(org.junit.Test)

Example 20 with ErrorType

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

the class OnCriticalErrorHandlerTestCase method acceptsCriticalChild.

@Test
public void acceptsCriticalChild() {
    ErrorType errorType = mock(ErrorType.class);
    when(error.getErrorType()).thenReturn(errorType);
    when(errorType.getParentErrorType()).thenReturn(CRITICAL_ERROR_TYPE);
    assertThat(handler.accept(muleEvent), is(true));
}
Also used : ErrorType(org.mule.runtime.api.message.ErrorType) Test(org.junit.Test)

Aggregations

ErrorType (org.mule.runtime.api.message.ErrorType)35 Test (org.junit.Test)19 SmallTest (org.mule.tck.size.SmallTest)9 SingleErrorTypeMatcher (org.mule.runtime.core.api.exception.SingleErrorTypeMatcher)8 Error (org.mule.runtime.api.message.Error)7 ComponentIdentifier (org.mule.runtime.api.component.ComponentIdentifier)6 ErrorTypeMatcher (org.mule.runtime.core.api.exception.ErrorTypeMatcher)6 ErrorTypeLocator (org.mule.runtime.core.privileged.exception.ErrorTypeLocator)6 ErrorTypeRepository (org.mule.runtime.api.exception.ErrorTypeRepository)5 Optional (java.util.Optional)4 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)4 MessagingException (org.mule.runtime.core.internal.exception.MessagingException)4 PrivilegedMuleContext (org.mule.runtime.core.privileged.PrivilegedMuleContext)4 LinkedList (java.util.LinkedList)3 List (java.util.List)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 Component (org.mule.runtime.api.component.Component)3 TypedException (org.mule.runtime.api.exception.TypedException)3 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)3 HashSet (java.util.HashSet)2