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

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