ToolJet/docs/versioned_docs/version-2.30.0/how-to/intentionally-fail-js-query.md
Abhinaba Adhikari fe086ac96c
Add new templates (#8907)
* update whitelist IP address and add warning in workspace constants to avoid usage in the client

* [docs] platform milestone 11 (#8847)

* [docs]reset password

* [docs]edit+archive flow

* [docs]updated docs in v2.29 and v2.30

* [docs]github ssouserinfo

* [docs] openid - id_token_encrypted

* Change docker image build's slack message

* [docs]archive/unarchive workspaces:superadmin (#8880)

* mention that workspace constants will not work with workspace constants (#8887)

* update release notes and project overview sidebar (#8884)

* add rgba example for timeline doc (#8892)

* update commands and solution for migration issues

* minor grammar fix

* [docs] revamped how-to guides (#8688)

* [docs]revamped howto: serverside pagination

* [docs]revamp howto: import ext. js libs

* [docs]revamp howto:run actions from js query

* [docs]revamp howto: intentionally fail js query

* updated run query at specified

* revamped how to: use to_py

* [docs]updated how to access users location

* updated howtos in v2.30

* Add new templates - batch 3

---------

Co-authored-by: Karan Rathod <karan.altcampus@gmail.com>
Co-authored-by: Adish M <44204658+adishM98@users.noreply.github.com>
Co-authored-by: Shubhendra Singh Chauhan <withshubh@gmail.com>
Co-authored-by: Adish M <adish.madhu@gmail.com>
Co-authored-by: Akshay <akshaysasidharan93@gmail.com>
2024-02-29 11:56:03 +05:30

37 lines
No EOL
1.4 KiB
Markdown

---
id: intentionally-fail-js-query
title: Intentionally Throwing an Error in RunJS for Debugging
---
In this step-by-step guide, we'll walk you through the process of creating a RunJS query that intentionally throws an error for debugging purposes.
<div style={{paddingTop:'24px', paddingBottom:'24px'}}>
### Creating the Error-Throwing RunJS Query
1. Create a new RunJS query by clicking the `+ Add` button on the query panel.
2. Paste the following code into the RunJS query editor. This code utilizes the `ReferenceError` constructor to intentionally generate an error.
```js
throw new ReferenceError('This is a reference error.');
```
</div>
<div style={{paddingTop:'24px', paddingBottom:'24px'}}>
### Adding an Event Handler for Failure
3. Now, enhance the query by adding an event handler that will display an alert when the query fails.
4. Click the "Run" button to execute the query and observe the intentional error being thrown.
Refer to the screencast below:
<div style={{textAlign: 'center'}}>
<img style={{ border:'0', marginBottom:'15px', borderRadius:'5px', boxShadow: '0px 1px 3px rgba(0, 0, 0, 0.2)' }} className="screenshot-full" src="/img/how-to/failjs/failjsn.gif" alt="reate a new RunJS query" />
</div>
</div>
By following these steps, you can effectively simulate errors in your RunJS queries, aiding in the debugging process and improving the overall robustness of your code.