The functions described here are packaged in the Runtime module. The module is included with Mule Runtime, but you must import it to your DataWeave code by adding the line import dw::Runtime to your header.

This module contains functions that allow you to interact with the DataWeave engine.

Functions

fail

fail(String): Nothing

Throws an exception with the specified message.

Example
1
2
3
4
%dw 2.0
import dw::Runtime
---
Runtime::fail("Error")
Output
Error

failIf

failIf(T, (value: T) → Boolean, String): T

Throws an exception with the specified message if the expression in the evaluator returns true. If not, return the value.

Example
1
2
3
4
5
%dw 2.0
import failIf from dw::Runtime
output application/json
---
{ "a" : "b" } failIf ("b" is String)
Output
Failed

locationString

locationString(Any): String

Returns the location string of a given value

prop

prop(String): String | Null

Returns the value of the property with the specified name or null if not defined

props

props(): Dictionary<String>

Returns all the properties configured for the underlying runtime

try

try(() → T): TryResult<T>

Evaluates the delegate (a lambda without inputs) and returns an object with the result or an error message.

Example
1
2
3
4
5
%dw 2.0
import try, fail from dw::Runtime
output application/json
---
try(fail)
Output
{
   "success": false,
   "error": {
     "kind": "UserException",
     "message": "Error",
     "location": "Unknown location",
     "stack": [

     ]
   }
}

wait

wait(T, Number): T

Stops the execution for the specified timeout (in milliseconds).

Example
1
2
3
4
5
%dw 2.0
import * from dw::Runtime
output application/json
---
{user: 1} wait 2000
Output
{
  "user": 1
}

Types

TryResult

Object with a result or error message. If success is false, it contains the error. If true, it provides the result.

Definition
1
{ success: Boolean, result?: T, error?: { kind: String, message: String, stack?: Array<String>, location?: String } }