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

# failIf

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

## failIf(T, (value: T) -> Boolean, String): T

Produces an error with the specified message if the expression in the evaluator returns `true`,
otherwise 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"
  }
}
```
