fix: comprehensive error handling and node-level properties validation (fixes #26)

Root cause: AI agents were placing error handling properties inside `parameters` instead of at node level

Major changes:
- Enhanced workflow validator to check for ALL node-level properties (expanded from 6 to 11)
- Added validation for onError property values and deprecation warnings for continueOnFail
- Updated all examples to use modern error handling (onError instead of continueOnFail)
- Added comprehensive node-level properties documentation in tools_documentation
- Enhanced MCP tool documentation for n8n_create_workflow and n8n_update_partial_workflow
- Added test script demonstrating correct node-level property usage

Node-level properties now validated:
- credentials, disabled, notes, notesInFlow, executeOnce
- onError, retryOnFail, maxTries, waitBetweenTries, alwaysOutputData
- continueOnFail (deprecated)

Validation improvements:
- Detects misplaced properties and provides clear fix examples
- Shows complete node structure when properties are incorrectly placed
- Type validation for all node-level boolean and string properties
- Smart error messages with correct placement guidance

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
czlonkowski
2025-07-09 20:39:24 +02:00
parent 66e032c2a0
commit eab3cc858e
12 changed files with 1638 additions and 138 deletions

View File

@@ -491,9 +491,11 @@ export class EnhancedConfigValidator extends ConfigValidator {
case 'strict':
// Keep everything, add more suggestions
if (result.warnings.length === 0 && result.errors.length === 0) {
result.suggestions.push('Consider adding error handling and timeout configuration');
result.suggestions.push('Consider adding error handling with onError property and timeout configuration');
result.suggestions.push('Add authentication if connecting to external services');
}
// Require error handling for external service nodes
this.enforceErrorHandlingForProfile(result, profile);
break;
case 'ai-friendly':
@@ -503,7 +505,64 @@ export class EnhancedConfigValidator extends ConfigValidator {
result.warnings = result.warnings.filter(w =>
w.type !== 'inefficient' || !w.property?.startsWith('_')
);
// Add error handling suggestions for AI-friendly profile
this.addErrorHandlingSuggestions(result);
break;
}
}
/**
* Enforce error handling requirements based on profile
*/
private static enforceErrorHandlingForProfile(
result: EnhancedValidationResult,
profile: ValidationProfile
): void {
// Only enforce for strict profile on external service nodes
if (profile !== 'strict') return;
const nodeType = result.operation?.resource || '';
const errorProneTypes = ['httpRequest', 'webhook', 'database', 'api', 'slack', 'email', 'openai'];
if (errorProneTypes.some(type => nodeType.toLowerCase().includes(type))) {
// Add general warning for strict profile
// The actual error handling validation is done in node-specific validators
result.warnings.push({
type: 'best_practice',
property: 'errorHandling',
message: 'External service nodes should have error handling configured',
suggestion: 'Add onError: "continueRegularOutput" or "stopWorkflow" with retryOnFail: true for resilience'
});
}
}
/**
* Add error handling suggestions for AI-friendly profile
*/
private static addErrorHandlingSuggestions(
result: EnhancedValidationResult
): void {
// Check if there are any network/API related errors
const hasNetworkErrors = result.errors.some(e =>
e.message.toLowerCase().includes('url') ||
e.message.toLowerCase().includes('endpoint') ||
e.message.toLowerCase().includes('api')
);
if (hasNetworkErrors) {
result.suggestions.push(
'For API calls, consider adding onError: "continueRegularOutput" with retryOnFail: true and maxTries: 3'
);
}
// Check for webhook configurations
const isWebhook = result.operation?.resource === 'webhook' ||
result.errors.some(e => e.message.toLowerCase().includes('webhook'));
if (isWebhook) {
result.suggestions.push(
'Webhooks should use onError: "continueRegularOutput" to ensure responses are always sent'
);
}
}
}