2.9 KiB
2.9 KiB
🔍 Node 7 "Format Build Response" - retry_count Error
🎯 Error Message
Problem in node 'Format Build Response'
Cannot read properties of undefined (reading 'retry_count')
[line 12]
🔍 Root Cause
Node 7 tries to access:
retry_count: $workflow.staticData.retry_count || 0
The problem:
$workflow.staticDatamight beundefinedon first execution- Even if it exists,
retry_countproperty might not be set yet - Node 7 runs BEFORE Node 8 "Increment Retry Counter" on first attempt
🛠️ Fix: Update Node 7 Code
In n8n editor:
- Open Node 7 "Format Build Response"
- Replace the code with this FIXED version:
// FIXED: Properly handle undefined staticData
const repoInfo = $('Extract Repo Info').item.json;
const buildStatus = $('Check Build Status').item.json;
// Safely get retry count from staticData
const retryCount = ($workflow.staticData && $workflow.staticData.retry_count) || 0;
const result = {
status: buildStatus.status,
repo: repoInfo.repo_full_name,
branch: repoInfo.branch,
commit: repoInfo.commit_sha ? repoInfo.commit_sha.substring(0, 8) : 'N/A',
message: buildStatus.message,
timestamp: new Date().toISOString(),
retry_count: retryCount
};
// Add emoji for status
if (result.status === 'SUCCESS') {
result.emoji = '✅';
} else if (result.status === 'FAILED') {
result.emoji = '❌';
} else {
result.emoji = '⚠️';
}
return result;
Key Changes:
- ✅ Safe access:
($workflow.staticData && $workflow.staticData.retry_count) || 0 - ✅ Default values: Handle undefined properties gracefully
- ✅ Commit hash: Add null check before
.substring()
🎯 What Will Happen After Fix
First execution (retry_count = 0):
{
"status": "SUCCESS",
"emoji": "✅",
"repo": "gitadmin/test-repo",
"branch": "main",
"commit": "abc123",
"message": "Build completed successfully",
"timestamp": "2025-12-01T18:45:00.000Z",
"retry_count": 0
}
After retries (retry_count = 1, 2, or 3):
{
"status": "SUCCESS",
"emoji": "✅",
"retry_count": 1,
...
}
🔄 Alternative: Initialize staticData in Node 1
You can also add this to Node 1 "Extract Repo Info" to ensure staticData is initialized:
// Add at the start of Node 1 code:
if (!$workflow.staticData) {
$workflow.staticData = {};
}
if ($workflow.staticData.retry_count === undefined) {
$workflow.staticData.retry_count = 0;
}
// Then continue with original code...
✅ Testing
After applying the fix:
- Save workflow
- Test with cURL:
curl -X POST https://n8n.oky.sh/webhook/openhands-enhanced \
-H "Content-Type: application/json" \
-d '{"repository": {"full_name": "test"}, "commits": [{"message": "Test"}]}'
- Check n8n Executions tab - should complete without errors!
- See JSON response with ✅ emoji in "Format Build Response" node