Urgent.News

What's breaking now, across thousands of outlets.

Tech

RFC 7807 Error Envelope with DataWeave Try Function

Problem My script failed when try lacked an explicit import from dw::Runtime . The runtime reported Unable to resolve reference of: try during execution. The documentation describes try as a function that returns a Result object for handling errors docs . Input { "order" : { "id" : "ORD-2001" , "total" : "12.5O" } } Working configuration %dw 2.0 // try() lives in dw::Runtime — not imported by…

In a recent incident, a script failed to execute due to a missing import for the try function within the DataWeave runtime. The runtime reported an error stating "Unable to resolve reference of: try" during execution.

The documentation clarifies that the try() function is part of the dw::Runtime module, which is not imported by default. To resolve this issue, the recommended solution is to explicitly import the try function from dw::Runtime at the beginning of every script that utilizes it.

The provided input included an order object with an id of ORD-2001 and a total of 12.5O. After applying the try function to convert the total to a Number, an error occurred because the value "12.5O" could not be coerced into a Number. The detail field in the output contained the message "Cannot coerce String (12.5O) to Number," while the errorKind field held the value "InvalidNumberException."

To prevent such resolution errors, it is crucial to always include the import try from dw::Runtime statement at the top of scripts that use the try function. By doing so, the script can execute successfully, and the output will contain appropriate fields like type, title, status, detail, instance, and errorKind, following the RFC 7807 Error Envelope with DataWeave Try Function specifications.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

More from Wednesday 9 September →