{"record":{"id":"07dfd2273486585f","repo":"Stirling-Tools/Stirling-PDF","slug":"expected-expectedformat-automate-automa","errorCode":null,"errorMessage":"Expected ${expectedFormat === \"automate\" ? \"Automate JSON (operations array)\" : \"Folder Scanning JSON (pipeline array)\"} but file looks like ${detected === \"automate\" ? \"Automate JSON\" : \"Folder Scanning JSON\"}.","messagePattern":"Expected (.+?) but file looks like (.+?)\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"frontend/editor/src/core/utils/automationConverter.ts","lineNumber":403,"sourceCode":"export function parseAutomationFile(\n  fileText: string,\n  toolRegistry: Partial<ToolRegistry>,\n  expectedFormat?: \"automate\" | \"folderScanning\",\n): ParsedAutomationImport {\n  let raw: unknown;\n  try {\n    raw = JSON.parse(fileText);\n  } catch (err) {\n    throw new Error(`File is not valid JSON: ${(err as Error).message}`, {\n      cause: err,\n    });\n  }\n\n  const detected = detectAutomationFormat(raw);\n  const format = expectedFormat ?? detected;\n\n  if (expectedFormat && detected !== \"unknown\" && detected !== expectedFormat) {\n    throw new Error(\n      `Expected ${\n        expectedFormat === \"automate\"\n          ? \"Automate JSON (operations array)\"\n          : \"Folder Scanning JSON (pipeline array)\"\n      } but file looks like ${\n        detected === \"automate\" ? \"Automate JSON\" : \"Folder Scanning JSON\"\n      }.`,\n    );\n  }\n\n  if (format === \"automate\") {\n    const result = parseAutomationConfigJson(raw, toolRegistry);\n    return { format: \"automate\", ...result };\n  }\n  if (format === \"folderScanning\") {\n    const result = parseFolderScanningConfig(raw, toolRegistry);\n    return { format: \"folderScanning\", ...result };\n  }","sourceCodeStart":385,"sourceCodeEnd":421,"githubUrl":"https://github.com/Stirling-Tools/Stirling-PDF/blob/9ef20dcab80b85041912f045e17a6aea1d08f969/frontend/editor/src/core/utils/automationConverter.ts#L385-L421","documentation":"Thrown by parseAutomationFile when expectedFormat was supplied and detectAutomationFormat disagreed: the detected format is concrete (not 'unknown') and differs from what the caller expected.","triggerScenarios":"The caller asked for 'automate' but the file has a pipeline[] (folder-scanning), or asked for 'folderScanning' but the file has operations[] (automate).","commonSituations":"User picked the wrong import type in the UI; the file was exported in the other format; a mismatch between the selected radio button and the file's actual shape.","solutions":["Let the user pick the correct format, or omit expectedFormat to use auto-detection.","Re-export the config in the desired format.","Inform the user which format was actually detected so they can correct their selection."],"exampleFix":"// before\nparseAutomationFile(text, toolRegistry, 'automate'); // file is folder-scanning -> throws\n\n// after\nconst detected = detectAutomationFormat(JSON.parse(text));\nparseAutomationFile(text, toolRegistry, detected ?? undefined);","handlingStrategy":"validation","validationCode":"const detected = detectAutomationFormat(JSON.parse(text.replace(/^\\uFEFF/, '')));\nif (expectedFormat && detected !== 'unknown' && detected !== expectedFormat) {\n  throw new Error(`File is ${detected}, not ${expectedFormat}. Switch the import type.`);\n}","typeGuard":"function formatMatches(text: string, expected: 'automate' | 'folderScanning'): boolean {\n  const d = detectAutomationFormat(JSON.parse(text.replace(/^\\uFEFF/, '')));\n  return d === 'unknown' || d === expected;\n}","tryCatchPattern":null,"preventionTips":["Default to auto-detection (omit expectedFormat) unless the user explicitly forces a format.","When forcing a format, pre-check with detectAutomationFormat and warn before throwing.","Tell users the detected format so they can fix their selection."],"tags":["automation","config","validation","format-detection"],"backgroundTag":null,"analyzedSha":"9ef20dcab80b85041912f045e17a6aea1d08f969","analyzedAt":"2026-08-13T22:11:39.827Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}