hc0re
hc0re

Reputation: 1996

Mule 4 and Dataweave: how to omit stacktrace when using fail() from dw::Runtime

I have a DataWeave message transformer, let's say:

%dw 2.0
import fail from dw::Runtime
output application/java
fun isValuePresent(value, message: String) = if ( value == null or isEmpty(value) ) fail(message) else value
---
{
    brand: isValuePresent(payload.document[0].brand, p('import.error.missing.brand')),
    ...

I also have an error handler for this kind of errors.

Errors in Mule have their properties, like: description or detailedDescription.

Now normally, when I am catching other errors (like those from is true component) - everything is fine, error.description holds my error message, everything is fine.

But when an error produced by fail() is produced, I get a very big error description message:

""my error message here
Trace:
  at fail (Unknown)
  at isValuePresent (line: 13, column: 85)
  at main (line: 23, column: 7)" evaluating expression: "%dw 2.0
import fail from dw::Runtime
output application/java
fun isValuePresent(value, message: String) = if ( value == null or isEmpty(value) ) fail(message) else value
---
{
    brand: isValuePresent(payload.document[0].brand, p('import.error.missing.brand')),
    ...
    ...
    etc, etc

It looks like the whole content of my dataweave script is added to the trace. And I just want to have:

my error message here
Trace:
  at fail (Unknown)
  at isValuePresent (line: 13, column: 85)
  at main (line: 23, column: 7)" evaluating expression: "%dw 2.0

Is it possible to achieve this? Or I have I made some mistakes when designing this behaviour? Is there a way to fix this?

Upvotes: 1

Views: 649

Answers (1)

aled
aled

Reputation: 25837

I don't think you can do anything about that. It is the way the error is reported with fail() and it is not customizable. Probably it depends on how DataWeave itself reports errors rather than fail() itself.

Upvotes: 0

Related Questions