Zie619/n8n-workflows · error · Error

→ → Unrecognized file name structure

Error message

${fileName} → ${baseName} → Unrecognized file name structure

What it means

Thrown by the 'Format Data' Code node in an automation-triggered file-ingestion workflow. It buckets incoming files into known categories (search_terms, campaigns, targeting, placement, budgets) by regex-testing the lowercased base filename. When no regex matches, the node throws with the offending fileName and derived baseName embedded in the message.

Solutions

  1. Rename the uploaded file so its base name contains one of the known keywords: search_term, campaign, targeting, placement, budget.
  2. Inspect the error message's fileName → baseName chain to see exactly what base string the node derived, then fix the source of that name (uploader or naming convention).
  3. Extend the `map` array with a new { key, regex } entry if a legitimate new file type must be supported.
  4. Replace the hard throw with routing to a quarantine/error branch (e.g. result['unrecognized'].push) plus a notification, if unknown files should not kill the run.

Example fix

// before
if (!mappedKey) {
  throw new Error(`${fileName} → ${baseName} → Unrecognized file name structure`);
}

// after (collect and flag instead of halting the whole batch)
if (!mappedKey) {
  result['unrecognized'] = result['unrecognized'] || [];
  result['unrecognized'].push({ fileName, reason: 'no matching keyword' });
  continue;
}
Defensive patterns

Strategy: type-guard

Validate before calling

const KNOWN = /search_term|campaign|targeting|placement|budget/;
const fileName = item.json.fileName || item.json.name || 'unknown_file';
const baseName = fileName.split('.')[0].replace(/\s+/g, '_').toLowerCase();
const recognized = KNOWN.test(baseName);

Type guard

function classifyFile(baseName) {
  const map = [
    { key: 'search_terms', regex: /search_term/ },
    { key: 'campaigns', regex: /campaign/ },
    { key: 'targeting', regex: /targeting/ },
    { key: 'placement', regex: /placement/ },
    { key: 'budgets', regex: /budget/ }
  ];
  return map.find(m => m.regex.test(baseName))?.key ?? null;
}

Try / catch

for (const item of items) {
  const key = classifyFile(baseNameOf(item));
  if (!key) { result['unrecognized'] = result['unrecognized'] || []; result['unrecognized'].push(item.json); continue; }
  (result[key] = result[key] || []).push(item.json);
}

Prevention

When it happens

Trigger: An uploaded file whose base name (after splitting at the first '.', lowercasing, trimming trailing digits/underscores) contains none of: 'search_term', 'campaign', 'targeting', 'placement', 'budget'. Examples: 'ad_creative_v2.csv', 'audience_list.xlsx', a temp file like '~$budgets.xlsx' split at first dot yielding '~$budgets' still matches budget, but 'report (1).json' or 'Untitled.json' do not. Also files with no extension or names like 'Budget-Final.v2.csv' (split at first dot gives 'budget-final' which still matches 'budget') — the real failures are genuinely off-vocabulary names.

Common situations: Marketers renaming template files ('Q4 budgts.xlsx' typo), uploading extra files (README, images, ~$ Excel lock files with the dot split producing unexpected fragments), double extensions truncating the meaningful part ('campaigns.xlsx.csv' → base 'campaigns' still matches), or new report types added to the source system that the map was never updated for.

Related errors


AI-assisted analysis of Zie619/n8n-workflows@94007c1445 (2026-08-15). Data as JSON: /api/errors/461d72417b3e2f11. Report an issue: GitHub.

Appendix: source

Thrown at workflows/Code/1301_Code_Extractfromfile_Automation_Triggered.json:167

      "type": "n8n-nodes-base.merge",
      "position": [
        1200,
        -800
      ],
      "parameters": {},
      "typeVersion": 3.1,
      "notes": "This merge node performs automated tasks as part of the workflow."
    },
    {
      "id": "cd23e23c-9bb7-4b8d-90ab-8917783cf1ab",
      "name": "Format Data",
      "type": "n8n-nodes-base.code",
      "position": [
        1420,
        -800
      ],
      "parameters": {
        "jsCode": "const result = {};\n\nfor (const item of items) {\n  const fileName = item.json.fileName || item.json.name || 'unknown_file';\n  const baseName = fileName\n    .split('.')[0]\n    .replace(/\\s+/g, '_')\n    .toLowerCase()\n    .replace(/\\s*\\(\\d+\\)$/, '')\n    .replace(/_+$/, '')\n    .trim();\n\n  // regex → result key\n  const map = [\n    { key: 'search_terms', regex: /search_term/ },\n    { key: 'campaigns',    regex: /campaign/     },\n    { key: 'targeting',    regex: /targeting/   },\n    { key: 'placement',    regex: /placement/   },\n    { key: 'budgets',      regex: /budget/      },\n  ];\n\n  const entry = map.find(m => m.regex.test(baseName));\n  const mappedKey = entry ? entry.key : null;\n\n  console.log('fileName:', fileName);\n  console.log('baseName:', baseName);\n  console.log('mappedKey:', mappedKey);\n\n  if (!mappedKey) {\n    throw new Error(`${fileName} → ${baseName} → Unrecognized file name structure`);\n  }\n  result[mappedKey] = result[mappedKey] || [];\n  result[mappedKey].push(item.json);\n}\n\nreturn [{ json: result }];\n\n\n\n"
      },
      "typeVersion": 2,
      "notes": "This code node performs automated tasks as part of the workflow."
    },
    {
      "id": "02172577-d867-45a4-96ea-eb105169deff",
      "name": "Set fileName",
      "type": "n8n-nodes-base.set",
      "position": [
        320,
        -800
      ],
      "parameters": {
        "options": {
          "dotNotation": true,
          "ignoreConversionErrors": false
        },
        "assignments": {

View on GitHub (pinned to 94007c1445)