Skip to content

Commit 872e3d4

Browse files
authored
update: error handler and trigger error handler (#1057)
* update * update * update
1 parent fe0610b commit 872e3d4

File tree

14 files changed

+216
-28
lines changed

14 files changed

+216
-28
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
slug: trigger-error-handlers
3+
version: v1.505.0
4+
title: Trigger error handlers
5+
tags: ['Error handling', 'Triggers', 'Workspace']
6+
description: Trigger error handlers now allow you to configure specific error handling for individual triggers. Override workspace error handlers with custom, Slack, Teams, or email notifications per trigger.
7+
features:
8+
[
9+
'Configure error handlers for individual triggers (HTTP routes, Webhooks, Kafka, SQS, WebSocket, Postgres, NATS, MQTT, GCP, Email)',
10+
'Override workspace error handlers with trigger-specific handling',
11+
'Support for custom scripts, Slack, Teams, and email error handlers',
12+
'Additional arguments and retry configuration for custom error handlers',
13+
'Works with scripts only (not flows)'
14+
]
15+
docs: /docs/core_concepts/error_handling#trigger-error-handlers
16+
---
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
slug: email-error-handlers
3+
version: v1.520.0
4+
title: Email error handlers
5+
tags: ['Error handling', 'Email', 'Workspace']
6+
description: Email error handlers are now available for workspace and trigger error handling. Send automated error notifications via email when jobs fail, supporting multiple recipients and integration with existing error handling workflows.
7+
features:
8+
[
9+
'Email error handlers for workspace-level error notifications',
10+
'Support for multiple email recipients with validation',
11+
'Available for both workspace and trigger-specific error handling',
12+
'Integration with existing Slack, Teams, and custom error handlers',
13+
'Self-hosted instances only (requires SMTP configuration)'
14+
]
15+
docs: /docs/core_concepts/error_handling#email-error-handler
16+
---

docs/advanced/17_email_triggers/index.mdx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,8 @@ export async function main(sender_address: string, email_body: string) {
8787

8888
From a script or flow [deployed](../../core_concepts/0_draft_and_deploy/index.mdx) page, you will find on the "Details & Triggers" - "Email" tab the email address to use.
8989

90-
![Trigger panel](./trigger_panel.png "Trigger panel")
90+
![Trigger panel](./trigger_panel.png "Trigger panel")
91+
92+
## Error handling
93+
94+
Email triggers support local error handlers that override workspace error handlers for specific triggers. See the [error handling documentation](../../core_concepts/10_error_handling/index.mdx#trigger-error-handlers) for configuration details and examples.

docs/core_concepts/10_error_handling/index.mdx

Lines changed: 144 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import DocCard from '@site/src/components/DocCard';
22

33
# Error handling
44

5-
There are 5 ways to do error handling in Windmill.
5+
There are multiple ways to handle errors in Windmill.
66

77
## try/catch inside a script
88

@@ -94,11 +94,18 @@ You can pick the Slack pre-set schedule error handler or define your own.
9494

9595
## Workspace error handler
9696

97-
Define a script or flow to be executed automatically in case of error in the workspace (e.g. a scheduled job fails to re-schedule).
97+
Configure automatic error handling for workspace-level errors (e.g. scheduled job failures, trigger failures without their own error handlers). Choose from built-in notification options or define custom error handling logic.
9898

99-
### Workspace error handler on Slack and Microsoft Teams
99+
Configure workspace error handlers from **Workspace Settings > Error Handler** tab. The system supports four types of error handlers:
100100

101-
On [Cloud plans and Self-Hosted & Enterprise Edition](/pricing), you can [connect workspace to Slack](../../integrations/slack.mdx) or [Microsoft Teams](../../integrations/teams.mdx) and enable an automated error handler on a given channel.
101+
### Slack error handler
102+
103+
Send error notifications to Slack channels. Requires workspace to be [connected to Slack](../../integrations/slack.mdx).
104+
105+
**Configuration:**
106+
- Enable/disable Slack error handler toggle
107+
- Specify Slack channel (without # prefix)
108+
- Available on [Cloud plans and Self-Hosted & Enterprise Edition](/pricing)
102109

103110
<iframe
104111
style={{ aspectRatio: '16/9' }}
@@ -110,49 +117,162 @@ On [Cloud plans and Self-Hosted & Enterprise Edition](/pricing), you can [connec
110117
className="border-2 rounded-lg object-cover w-full dark:border-gray-800"
111118
></iframe>
112119

113-
<br />
120+
### Microsoft Teams error handler
114121

115-
### Custom workspace error handler
122+
Send error notifications to Microsoft Teams channels. Requires workspace to be [connected to Teams](../../integrations/teams.mdx).
116123

117-
You can also define a custom script or flow to be executed automatically in case of error in the workspace.
124+
**Configuration:**
125+
- Enable/disable Teams error handler toggle
126+
- Select from available Teams channels dropdown
127+
- Available on [Cloud plans and Self-Hosted & Enterprise Edition](/pricing)
118128

119-
From the workspace settings, on the "Error handler" tab and pick a script or flow.
129+
### Email error handler
120130

121-
![Workspace Error handler](./workspace_error_handler.png 'Workspace Error handler')
131+
Send error notifications via email to specified recipients.
122132

123-
The following args will be passed to the error handler:
133+
**Configuration:**
134+
- Specify email addresses to receive error notifications
135+
- Only available on Self-Hosted instances (not available on Cloud)
136+
- Requires SMTP configuration
124137

125-
- path: The path of the script or flow that errored.
126-
- email: The email of the user who ran the script or flow that errored.
127-
- error: The error details.
128-
- job_id: The job id.
129-
- is_flow: Whether the error comes from a flow.
130-
- workspace_id: The workspace id of the failed script or flow.
138+
### Custom error handler
131139

132-
The Error handler will be executed by the automatically created group g/error_handler. If your error handler requires variables or resources, you need to add them to the group.
140+
Execute custom scripts or flows as error handlers for advanced error handling logic.
133141

134-
Here is a template for your workspace error handler:
142+
**Configuration:**
143+
- Script or flow selection via script picker
144+
- Additional arguments can be configured if the chosen script or flow has parameters
145+
- Template creation options
146+
147+
**Parameters passed to custom error handlers:**
148+
149+
All custom workspace error handlers receive the following base parameters:
150+
151+
- `workspace_id`: The workspace id where the error occurred
152+
- `job_id`: The job id of the failed execution
153+
- `path`: The path of the script or flow that errored
154+
- `is_flow`: Whether the error comes from a flow
155+
- `started_at`: When the failed job started
156+
- `email`: The email of the user who ran the script or flow that errored
157+
- `schedule_path`: The schedule path (only present if the error comes from a scheduled job)
158+
159+
**Custom error handler template:**
135160

136161
```ts
137-
// Workspace error handler template
162+
// Custom workspace error handler template
138163

139164
export async function main(
165+
workspace_id: string, // The workspace id where the error occurred
166+
job_id: string, // The job id of the failed execution
140167
path: string, // The path of the script or flow that errored
168+
is_flow: boolean, // Whether the error comes from a flow
169+
started_at: string, // When the failed job started
141170
email: string, // The email of the user who ran the script or flow that errored
142-
error: object, // The error details
143-
job_id: string, // The job id
171+
schedule_path?: string // The schedule path (only present if error from scheduled job)
172+
) {
173+
const run_type = is_flow ? 'flow' : 'script';
174+
console.log(
175+
`Workspace error: ${run_type} ${path} run by ${email} failed in workspace ${workspace_id}`
176+
);
177+
console.log(`Job ${job_id} started at ${started_at}`);
178+
179+
if (schedule_path) {
180+
console.log(`Scheduled job from: ${schedule_path}`);
181+
}
182+
183+
// Add your custom error handling logic here
184+
// Examples: send to external monitoring, create incidents, etc.
185+
186+
// Note: The actual error details are available through the job context
187+
// and can be retrieved using Windmill's job APIs if needed
188+
189+
return { handled: true, workspace_id, job_id };
190+
}
191+
```
192+
193+
---
194+
195+
From the workspace settings, go to the "Error handler" tab and select your preferred error handler type.
196+
197+
![Workspace Error handler](./workspace_error_handler.png 'Workspace Error handler')
198+
199+
### Error handler execution
200+
201+
- Error handlers are executed by the automatically created group `g/error_handler`
202+
- If your error handler requires variables or resources, add them to the `g/error_handler` group
203+
- Error handlers run as different users depending on type:
204+
- Custom, Slack, Teams error handlers: `[email protected]`
205+
- Email error handlers: `[email protected]`
206+
- The system prevents infinite loops by not triggering error handlers for error handler jobs themselves
207+
208+
### Advanced configuration
209+
210+
**Skip error handler for cancelled jobs:**
211+
Enable the "Do not run error handler for canceled jobs" option to prevent error handlers from triggering when jobs are manually cancelled.
212+
213+
214+
## Trigger error handlers
215+
216+
Each trigger type (HTTP routes, Webhooks, Kafka, SQS, WebSocket, Postgres, NATS, MQTT, GCP, Email) can have its own local error handler configured. If a trigger-specific error handler is defined, it will be used for that trigger instead of the workspace error handler. **Trigger error handlers only work for scripts** (not flows).
217+
218+
219+
### Configuring trigger error handlers
220+
221+
When creating or editing a trigger, you can configure the same error handler options as workspace error handlers:
222+
- **Custom script or flow**: Execute your own custom error handling logic
223+
- **Slack integration**: Send error notifications to Slack channels
224+
- **Microsoft Teams integration**: Send error notifications to Teams channels
225+
- **Email notifications**: Send error alerts via email to specified recipients
226+
227+
For each trigger error handler, you can also specify:
228+
- **Error handler arguments**: Additional arguments for the custom error handler (only configurable if the chosen script or flow has parameters)
229+
- **Retry configuration**: Number of retries and retry strategy before invoking the error handler
230+
231+
### Parameters passed to trigger error handlers
232+
233+
Trigger error handlers receive the following base parameters:
234+
- `error`: The error details from the failed job
235+
- `path`: The path of the script or flow that errored
236+
- `is_flow`: Whether the error comes from a flow (always `false` for triggers)
237+
- `trigger_path`: The trigger path in format `<trigger_kind>/<trigger_path>` (e.g., `http_trigger/my-webhook`, `kafka_trigger/my-topic`)
238+
- `workspace_id`: The workspace id where the error occurred
239+
- `email`: The email of the user who triggered the execution
240+
- `job_id`: The job id of the failed execution
241+
- `started_at`: When the failed job started
242+
243+
If using a custom trigger error handler, additional custom arguments can be passed via the error handler configuration.
244+
245+
### Example trigger error handler
246+
247+
Here's a template for a trigger error handler:
248+
249+
```ts
250+
// Trigger error handler template
251+
export async function main(
252+
error: object, // The error details from the failed job
253+
path: string, // The path of the script or flow that errored
144254
is_flow: boolean, // Whether the error comes from a flow
145-
workspace_id: string // The workspace id of the failed script or flow
255+
trigger_path: string, // The trigger path in format <trigger_kind>/<trigger_path>
256+
workspace_id: string, // The workspace id where the error occurred
257+
email: string, // The email of the user who triggered the execution
258+
job_id: string, // The job id of the failed execution
259+
started_at: string // When the failed job started
146260
) {
147261
const run_type = is_flow ? 'flow' : 'script';
148262
console.log(
149-
`An error occurred with ${run_type} ${path} run by ${email} in workspace ${workspace_id}`
263+
`Trigger error: ${run_type} ${path} run by ${email} failed in workspace ${workspace_id}`
150264
);
151-
console.log(error);
265+
console.log(`Trigger: ${trigger_path}, Job ID: ${job_id}, Started: ${started_at}`);
266+
console.log('Error details:', error);
267+
268+
// Add custom logic for trigger-specific error handling
269+
152270
return error;
153271
}
154272
```
155273

274+
This allows you to customize error handling behavior per trigger while maintaining consistent fallback to workspace-level error handling.
275+
156276
## Instance error handler
157277

158278
You can define a script to be executed automatically in case of error in your instance (all workspaces).
92.3 KB
Loading
Binary file not shown.

docs/core_concepts/39_http_routing/index.mdx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,4 +397,8 @@ async function verifySignature(signature: string, body: string, timestamp?: stri
397397
}
398398
}
399399
```
400-
> ℹ️ When using **Custom Script**, the `raw_body` option is automatically enabled.
400+
> ℹ️ When using **Custom Script**, the `raw_body` option is automatically enabled.
401+
402+
## Error handling
403+
404+
HTTP routes support local error handlers that override workspace error handlers for specific routes. See the [error handling documentation](../10_error_handling/index.mdx#trigger-error-handlers) for configuration details and examples.

docs/core_concepts/40_websocket_triggers/index.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ Windmill supports the following filter:
8686

8787
![Filters](./filters.png 'Filters')
8888

89+
## Error handling
90+
91+
WebSocket triggers support local error handlers that override workspace error handlers for specific triggers. See the [error handling documentation](../10_error_handling/index.mdx#trigger-error-handlers) for configuration details and examples.
92+
8993

9094

9195

docs/core_concepts/41_kafka_triggers/index.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,7 @@ export async function main(message_content: string, topic: string) {
5656
// do something with the message content and topic
5757
}
5858
```
59+
60+
## Error handling
61+
62+
Kafka triggers support local error handlers that override workspace error handlers for specific triggers. See the [error handling documentation](../10_error_handling/index.mdx#trigger-error-handlers) for configuration details and examples.

docs/core_concepts/45_nats_triggers/index.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,7 @@ A [durable push-consumer](https://docs.nats.io/nats-concepts/jetstream/consumers
7676
If one already exists, it will be overwritten.
7777
The consumer name is also used as the `DeliverSubject`, so make sure it's unique.
7878

79+
## Error handling
80+
81+
NATS triggers support local error handlers that override workspace error handlers for specific triggers. See the [error handling documentation](../10_error_handling/index.mdx#trigger-error-handlers) for configuration details and examples.
82+

0 commit comments

Comments
 (0)