Error Handling and The Error Trigger
Relevant source files
The following files were used as context for generating this wiki page:
- packages/cli/src/errors/workflow-crashed.error.ts
- packages/core/src/errors/error-reporter.ts
- packages/frontend/editor-ui/src/constants.ts
- packages/nodes-base/nodes/ErrorTrigger/ErrorTrigger.node.json
- packages/nodes-base/nodes/Mattermost/Mattermost.node.json
- packages/nodes-base/nodes/StopAndError/StopAndError.node.json
- packages/workflow/src/errors/node.error.ts
In n8n, robust error handling is facilitated by a mechanism that allows a failed workflow execution to trigger a separate, dedicated "Error Workflow". This enables developers to build custom logic for notifications, logging, or recovery actions when a workflow encounters a problem. The cornerstone of this feature is the Error Trigger node, which serves as the starting point for any workflow designed to handle the failure of another.
This system provides a decoupled way to manage exceptions. Instead of cluttering a primary workflow with complex error-handling branches, you can centralize error management in one or more specialized workflows. These error workflows receive contextual information about the failure, allowing for detailed analysis and response.
The Error Trigger Node
The Error Trigger node is a special trigger that initiates a workflow when another workflow on the same n8n instance fails. It is the designated entry point for any workflow that is set as an "Error Workflow" in the instance settings or within another workflow's settings.
Sources: packages/nodes-base/nodes/ErrorTrigger/ErrorTrigger.node.json
Node Characteristics
| Property | Value | Description | Source |
|---|---|---|---|
| Node Type | n8n-nodes-base.errorTrigger | The unique identifier for this node type. | packages/frontend/editor-ui/src/constants.ts:143 |
| Category | Development, Core Nodes | The node is classified under these categories in the UI. | packages/nodes-base/nodes/ErrorTrigger/ErrorTrigger.node.json:5 |
| Subcategory | Other Trigger Nodes | A more specific grouping within the Core Nodes category. | packages/nodes-base/nodes/ErrorTrigger/ErrorTrigger.node.json:19-21 |
| Activatable | No | This trigger cannot be manually activated or deactivated; it is controlled by the system's error handling settings. | packages/frontend/editor-ui/src/constants.ts:258-263 |
Error Handling Flow
The following diagram illustrates the basic flow of how a failing workflow triggers an error workflow.
This diagram shows a main workflow failing at a certain step, which results in an "Execution Failure" event. This event then triggers the "Error Workflow", which starts with the ErrorTrigger node.
Sources: packages/nodes-base/nodes/ErrorTrigger/ErrorTrigger.node.json:4, packages/nodes-base/nodes/Mattermost/Mattermost.node.json
Causing and Handling Errors
Errors can occur for various reasons, such as a node failing to execute, an external API being unavailable, or data being in an unexpected format. Additionally, n8n provides a specific node to intentionally stop a workflow and flag it as an error.
The StopAndError Node
The n8n-nodes-base.stopAndError node is a utility node that explicitly halts the workflow's execution and marks it as failed. This is useful for implementing custom validation logic where a workflow should not proceed if certain conditions are not met.
| Property | Value | Description | Source |
|---|---|---|---|
| Node Type | n8n-nodes-base.stopAndError | The unique identifier for this node. | packages/nodes-base/nodes/StopAndError/StopAndError.node.json:2 |
| Category | Core Nodes, Utility | The node is classified under these categories. | packages/nodes-base/nodes/StopAndError/StopAndError.node.json:5 |
| Aliases | Throw error, Error, Exception | Alternative search terms for the node in the editor. | packages/nodes-base/nodes/StopAndError/StopAndError.node.json:11 |
Using this node will trigger the configured Error Workflow, just like any other execution failure.
Sources: packages/nodes-base/nodes/StopAndError/StopAndError.node.json
Error Data Structure
When an error workflow is triggered, it receives a payload containing information about the failed execution. This context is crucial for logging and debugging. The error object typically includes details about the error message, the node that failed, and the execution itself.
The system defines several custom error classes to structure this information.
Error Class Diagram
This diagram shows the relationship between different error classes in the system.
This diagram illustrates that a WorkflowCrashedError is a type of NodeError, indicating a structured approach to error reporting.
Sources: packages/workflow/src/errors/node.error.ts, packages/cli/src/errors/workflow-crashed.error.ts
The NodeError class is fundamental, capturing details about the node and execution context at the time of failure.
Sources: packages/workflow/src/errors/node.error.ts:11-15
Frontend Integration
The n8n frontend is aware of the error handling mechanism and provides constants and links to guide the user.
UI Constants
The constants.ts file in the editor-ui package defines several key values related to error handling.
| Constant | Value | Purpose |
|---|---|---|
ERROR_TRIGGER_NODE_TYPE | 'n8n-nodes-base.errorTrigger' | Defines the type name for the Error Trigger node. |
NON_ACTIVATABLE_TRIGGER_NODE_TYPES | [..., 'n8n-nodes-base.errorTrigger', ...] | An array that includes the Error Trigger, signifying it cannot be toggled on/off by the user. |
ERROR_WORKFLOW_DOCS_URL | https://docs.n8n.io/flow-logic/error-handling/#create-and-set-an-error-workflow | A direct link to the documentation for creating error workflows. |
Sources: packages/frontend/editor-ui/src/constants.ts:143, 260, 120
This configuration ensures that the Error Trigger node is handled correctly within the editor interface, distinguishing it from other trigger types that have activation controls.
Summary
The error handling system in n8n, centered around the Error Trigger node, provides a powerful and flexible way to manage workflow failures. By decoupling error logic into separate, dedicated workflows, users can create sophisticated and maintainable automation for monitoring, alerting, and recovery. The system provides detailed contextual data about each failure, which can be used within the error workflow to take specific actions, such as sending a detailed notification to a Mattermost channel or logging the error to a database. The StopAndError node further enhances this by allowing for programmatic and conditional failure states within a workflow's logic.
Sources: packages/nodes-base/nodes/ErrorTrigger/ErrorTrigger.node.json, packages/nodes-base/nodes/StopAndError/StopAndError.node.json, packages/nodes-base/nodes/Mattermost/Mattermost.node.json:28