---
schema_version: "1"
id: 344000ee00031522386af4077aefba2f9a2367c754550355b1a252389c972716
title: failIf
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/2.12/dw-runtime-functions-failif.md
canonical_url: https://docs.mulesoft.com/dataweave/2.12/dw-runtime-functions-failif
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 4b71c0b8c2e3ef859f428afdc553ee687256ec83c96cef60b20e7de9409e2ecf
description: MuleSoft Documentation Site
release: "2.12"
latest: false
---
---
product: DataWeave
version: 2.12
---

# failIf

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

## failIf<T>(value: T, evaluator: (value: T) -> Boolean, message: String = 'Failed'): T

Produces an error with the specified message if the expression in the evaluator returns `true`.
Otherwise, the function returns the value.

### Parameters

<table><colgroup><col> <col></colgroup><thead><tr><th>Name</th><th>Description</th></tr></thead><tbody><tr><td><p><code>value</code></p></td><td><p>The value to return only if the <code>evaluator</code> expression is <code>false</code>.</p></td></tr><tr><td><p><code>evaluator</code></p></td><td><p>Expression that returns <code>true</code> or <code>false</code>.</p></td></tr></tbody></table>

### Example

This example produces a runtime error (instead of a SUCCESS message) because the expression
`isEmpty(result)` is `true`. It is `true` because an empty object is passed through variable
`result`.

#### Source

```DataWeave
%dw 2.0
import failIf from dw::Runtime
var result = {}
output application/json
---
{ "result" : "SUCCESS" failIf (isEmpty(result)) }
```

#### Output

```TXT
ERROR 2018-07-29 11:56:39,988 ...
**********************************
Message               : "Failed
```

Alternatively, the function outputs the value.

#### Source

```DataWeave
%dw 2.0
import failIf from dw::Runtime
var result = {"a":"test"}
output application/json
---
{ "result" : result failIf isEmpty($) }
```

#### Output

```JSON
{
  "result": {
    "a": "test"
  }
}
```
