MuleSoft User Land

Controlling Logging Level

Example:

<logger level="ERROR" category="app" message='Error Message'/>

Category is a user defined value. If it is specified, then this value can be referenced in src/main/resources/log4j2.xml configuration file.

For example, the following statement can be added under Loggers element:

<AsyncLogger name="app" level="TRACE"/>

Raising Errors

Error can be raised with element:

<raise-error type="APP:SIGNATURE_VERIFICATION" description="Signatures don't match"/>

This automatically generates a new error type. The way to match error handler to all “APP” errors:

<on-error-propagate type="ANY" when='error.errorType.namespace = "APP"'>
	<set-payload value="#[error.description]" doc:name="to error description" />
</on-error-propagate>

The statement when='error.errorType.namespace = "APP" matches error namespace APP.

There is a significant reason to set payload to to error.description. By using a custom error type APP we make it possible to identify a subset of errors with error description set to a value that’s safe to expose to the caller.

MUnit in AnyPoint Studio

If MUnit fails to start check logs.

Related:

  1. [Official MUnit Documentation][munit_documentation].
  2. MuleSoft [MUnit Tutorial][munit_tutorial].

Mocking in MUnit

References:

  1. [Mocking and Testing in Mule 4][mule_mocking] has pretty good XML example.
  2. Less interesting [An example of how to create an MUnit 2 test][munit_example].

Unable to Run MUnit

I had something like this in logs:

org.mule.tooling.client.api.exception.ToolingException: Error while creating application from url: file:/C:/Users
java.lang.RuntimeException: There was an issue resolving the dependency tree for the artifact [C:\Users

It works from command line.

Solution

Not sure which change made an impact:

  1. Use external mvn to make sure the same mvn version is used in command line and in Anypoint.

To set external maven go to “Window” -> “Preferences” -> “Anypoint Studio” -> “Maven”. Uncheck use embedded Maven installation and set to your mvn home directory.

Use “Test Maven Configuration” button to verify the right version is used and the expected version of Java Runtime is reported.

If the wrong version of Java Runtime is reported, use the following instructions to change.

  1. Set proper Java Runtime in Anypoint Studio.

Go to “Window” -> “Preferences” -> Java -> “Installed JREs” and set default.

Related:

Custom Connectors

Errors

For Mule 4.2 just follow template outlined in https://docs.mulesoft.com/mule-sdk/1.1/errors.

Troubleshooting

Error thrown “was not registered in the Error Repository”

Example Error (reformatted):

org.mule.runtime.core.internal.message.ErrorBuilder$ErrorImplementation { 
	description=The component 'opName' from the connector 'connectorName' attempted to throw 'NEW_TYPE:NEW_EXCEPTION', 
	but it was not registered in the Error Repository detailedDescription=The component 'opName' 
	from the connector 'connectorName' attempted to throw 'NEW_TYPE:NEW_EXCEPTION', 
	but it was not registered in the Error Repository 
	errorType=MULE:UNKNOWN 
	cause=org.mule.runtime.api.exception.MuleRuntimeException errorMessage=- childErrors=[] 
}

Solution

Make sure ConnectorExtension Java class is marked with

@ErrorTypes(CustomError.class)

where CustomError class is a custom class implementing ErrorTypeDefinition.

See [Errors Definition][errors_definition].

The component ‘opName’ from the connector ‘connectorName’ attempted to throw ‘NEW_TYPE:NEW_NAME’, but only [] errors are allowed

Solution

Check that operation marks method with

@Throws(MyCustomErrorsProvider.class)

See [Errors Definition][errors_definition].