You called the function '++' with these arguments:
1: Null (null)
2: String (" A text")
But it expects one of these combinations:
(Array, Array)
(Date, Time)
(Date, LocalTime)
(Date, TimeZone)
(LocalDateTime, TimeZone)
(LocalTime, Date)
(LocalTime, TimeZone)
(Object, Object)
(String, String)
(Time, Date)
(TimeZone, LocalDateTime)
(TimeZone, Date)
(TimeZone, LocalTime)
1| payload.message ++ " A text"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Trace:
at ++ (line: 1, column: 1)
at main (line: 1, column: 17)
Troubleshooting a Failing DataWeave Script
DataWeave 2.1 is compatible with Mule 4.1. Standard Support for Mule 4.1 ended on November 2, 2020, and this version of Mule will reach its End of Life on November 2, 2022, when Extended Support ends. Deployments of new applications to CloudHub that use this version of Mule are no longer allowed. Only in-place updates to applications are permitted. MuleSoft recommends that you upgrade to the latest version of Mule 4 that is in Standard Support so that your applications run with the latest fixes and security enhancements. |
When you troubleshoot a failing script, one challenge to reproducing an error is having the same inputs the script had when it executed, especially in production environments where inputs can change unexpectedly. Therefore, it’s important to capture the inputs going into a script debugging or using loggers. Often, the failures occur because the input coming from another component upstream is not valid. You can find here a listing of the most common DataWeave errors and how to overcome them.
DataWeave Exceptions
There are a number of common DataWeave exceptions or errors you might encounter.
Incorrect Arguments
When a function is called with the incorrect kind of argument, it throws the
exception, org.mule.weave.v2.exception.UnsupportedTypeCoercionException
.
Causes of this exception include:
Function Does Not Accept Null Argument
The most common cause of this exception occurs when one of the arguments is
Null
and the function does not accept Null
as an argument. This issue
results in an error message similar to the following:
One way to resolve this issue uses the default
operator. For example,
using payload.message default "" ++ " A text"
appends empty text when the
when the message is null.
MIME Type Is Not Set
When the MIME type is not set, you receive an error message similar to the following:
You called the function 'Value Selector' with these arguments:
1: String ("{\"message\": 123})"
2: Name ("message")
But it expects one of these combinations:
(Array, Name)
(Array, String)
(Date, Name)
(DateTime, Name)
(LocalDateTime, Name)
(LocalTime, Name)
(Object, Name)
(Object, String)
(Period, Name)
(Time, Name)
1| payload.message
^^^^^^^^^^^^^^^
Trace:
at main (line: 1, column: 1)
When no MIME type is set on the payload, the MIME type defaults to
application/java
, and the content is handled as a String
instead of a
JSON object.
Output Mismatch When Undefined
Unlike transformations, DataWeave expressions do not require you to define an output format because DataWeave can infer the output based on the expression and the variables you use. Occasionally, the inference process results in a mismatch between the inferred type and the expected type. To resolve this issue, you must make the output explicit. Common examples of this situation occur when:
Extract Data from XML
When extracting a String, for example, from an XML payload with the expression payload.order.product.model
, DataWeave infers an XML output based on the payload format. In such cases, an error similar to the following one occurs:
"Trying to output non-whitespace characters outside main element tree (in prolog or epilog), while writing Xml.
Trace:
at main (Unknown)" evaluating expression: "payload.order.product.model".
For such an error, you must make the output format explicit, for example: output text/plain --- payload.order.product.model
.
Handle Multipart Entries
A common inference error occurs with multipart data, which has a very specific structure. Consider a multipart payload and the expression dw::core::Objects::keySet(payload.parts)
. Without an explicit output format, DataWeave must infer, based on the payload type, that you intend to output multipart content. In this case, an error similar to the following is thrown:
"Expecting type is {
preamble?: String,
parts: {
_*: {
headers: Object,
content: Any
}
}
} but got Array, while writing MultiPart.
Trace:
at main (Unknown)" evaluating expression: "dw::core::Objects::keySet(payload.parts)".
To resolve this issue, you must define an output format, for example: output application/json --- dw::core::Objects::keySet(payload.parts)
Manipulate Text Data
You can use text data to create a more complex object. However, if you do not define the output format for the input text data, DataWeave infers that it must use the plain text writer for the output. The expression payload splitBy ' '
, for example, will fail with an error similar to:
"Text plain writer is unable to write Array.
Reason:
Cannot coerce Array (["hey", "there"]) to String
Trace:
at main (Unknown), while writing TextPlain.
Trace:
at main (Unknown)" evaluating expression: "payload splitBy ' '".
Making the output explicit solves the issue: output application/java --- payload splitBy ' '