MuleSoft · DataWeave
Cannot coerce String to Date
Short answer
This DataWeave error means a String could not be converted to a Date because the text is not a valid date for the format and parsing mode in use. Correct the input value, or pick a parsing mode that fits how strict you need to be.
VerifiedLast verified
01Error text
Cannot coerce String (02/31/2020) to Date, caused by: Text '02/31/2020' could not be parsed: Invalid date 'FEBRUARY 31'02Likely causes
- The text does not represent a real date. The docs' example is
02/31/2020, which fails withInvalid date 'FEBRUARY 31'. - The coercion uses the STRICT mode, which returns an error on an invalid date. The LENIENT and SMART modes autocorrect the date, each in a different way.
03How to fix it
- Read the message. It quotes the text that failed and the reason it could not be parsed.
- Check that the input value is a real date and that it matches the format used in the coercion.
- Decide whether invalid dates should fail. If they should, keep STRICT and correct or reject the bad input before the coercion.
- If an autocorrected date is acceptable, set another mode in the coercion, for example
'02/31/2020' as Date {mode: "LENIENT", format: 'MM/dd/uuuu'}. In the docs' example LENIENT returns03/02/2020and SMART returns02/29/2020.
iNotes
The values in the error text are the example from the DataWeave documentation. Your message quotes your own input.
04Official documentation
→Related errors
- You called the function '++' with these argumentsThis DataWeave error means a function was called with a kind of argument it does not accept, most often null. Find which argument is Null in the list the message prints, then give it a fallback with the default operator.
- MULE:EXPRESSIONMULE:EXPRESSION means an error occurred while Mule evaluated a DataWeave expression. Find the expression named in the log, check the values it reads for nulls or wrong types, and add a default or a handler.
Test every fix in a non-production environment before you apply it to production. See how entries are verified.
More for MuleSoft work:Open MuleSoft jobsMuleSoft rates and salariesHire a senior MuleSoft developer