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

# 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" : failIf(result, isEmpty) }
```

#### 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"
  }
}
```
