KEEP LEARNING
Build the bigger picture.
The Workflow Engineer connects individual n8n concepts to testing, deployment and running a complete workflow.
Tips > Reliability & Performance
When your workflow detects an invalid state that should not continue -- bad input data, missing prerequisites, or a violated business rule -- use the Stop
The Stop and Error node halts a workflow deliberately with a clear, descriptive message when it detects an invalid state, such as bad input or a violated business rule. Unlike an unexpected crash, it is a controlled stop that documents exactly what went wrong, and it is visible on the canvas so anyone reading the workflow sees the intent.
When your workflow detects an invalid state that should not continue -- bad input data, missing prerequisites, or a violated business rule -- use the Stop and Error node to halt execution with a clear, descriptive message. This is different from an unexpected error; it is a deliberate, controlled stop that communicates exactly what went wrong.
Real-world example: An invoice processing workflow receives data from a webhook. Before processing, it checks that the invoice total matches the sum of line items. If they do not match, the workflow should stop immediately with a clear message rather than processing bad data.
Workflow structure:
[Webhook] --> [Code: Validate Invoice] --> [IF: Valid?]
|
+-------+-------+
| |
[True] [False]
| |
[Process Invoice] [Stop and Error]Validation Code node:
// Code node: "Validate Invoice"
const invoice = $input.first().json.body;
const errors = [];
// Check required fields
if (!invoice.invoice_id) errors.push('Missing invoice_id');
if (!invoice.customer_id) errors.push('Missing customer_id');
if (!invoice.line_items || invoice.line_items.length === 0) {
errors.push('No line items');
}
// Check total matches line items
if (invoice.line_items && invoice.total !== undefined) {
const calculatedTotal = invoice.line_items.reduce(
(sum, item) => sum + (item.quantity * item.unit_price), 0
);
const roundedCalculated = Math.round(calculatedTotal * 100) / 100;
const roundedTotal = Math.round(invoice.total * 100) / 100;
if (roundedCalculated !== roundedTotal) {
errors.push(
`Total mismatch: stated ${roundedTotal}, calculated ${roundedCalculated}`
);
}
}
return [{
json: {
valid: errors.length === 0,
errors,
invoice
}
}];Stop and Error node configuration:
# Stop and Error node settings
Error Type: Workflow
Error Message: >
Invoice validation failed for invoice {{ $json.invoice.invoice_id }}:
{{ $json.errors.join('; ') }}.
Workflow halted to prevent processing invalid data.
Source customer: {{ $json.invoice.customer_id }}.The error message appears in:
- The execution log (with full details)
- The Error Workflow notification (if configured)
- The Respond to Webhook response (if using Respond to Webhook node on the error branch)Tip: Stop and Error vs. throwing in Code node Both halt the workflow, but Stop and Error is a visible node in the canvas that clearly communicates intent to anyone reading the workflow. It also provides a structured error message. Throwing an error in a Code node works but looks like a bug rather than intentional behavior.
Use Stop and Error as guardrails throughout your workflow to catch invalid states early and communicate clearly why processing was halted.
Related: Use "Pin Data" to Freeze Node Output · Break Large Workflows into Sub-Workflows
KEEP LEARNING
The Workflow Engineer connects individual n8n concepts to testing, deployment and running a complete workflow.
APPLY IT TO YOUR SYSTEM
Bring the process, the tools involved and an example of where the current workflow gets stuck.