Stirling-Tools/Stirling-PDF · warning · Error
Expected ${expectedFormat === "automate" ? "Automate JSON (o
Error message
Expected ${expectedFormat === "automate" ? "Automate JSON (operations array)" : "Folder Scanning JSON (pipeline array)"} but file looks like ${detected === "automate" ? "Automate JSON" : "Folder Scanning JSON"}. What it means
Thrown by parseAutomationFile when expectedFormat was supplied and detectAutomationFormat disagreed: the detected format is concrete (not 'unknown') and differs from what the caller expected.
Source
Thrown at frontend/editor/src/core/utils/automationConverter.ts:403
export function parseAutomationFile(
fileText: string,
toolRegistry: Partial<ToolRegistry>,
expectedFormat?: "automate" | "folderScanning",
): ParsedAutomationImport {
let raw: unknown;
try {
raw = JSON.parse(fileText);
} catch (err) {
throw new Error(`File is not valid JSON: ${(err as Error).message}`, {
cause: err,
});
}
const detected = detectAutomationFormat(raw);
const format = expectedFormat ?? detected;
if (expectedFormat && detected !== "unknown" && detected !== expectedFormat) {
throw new Error(
`Expected ${
expectedFormat === "automate"
? "Automate JSON (operations array)"
: "Folder Scanning JSON (pipeline array)"
} but file looks like ${
detected === "automate" ? "Automate JSON" : "Folder Scanning JSON"
}.`,
);
}
if (format === "automate") {
const result = parseAutomationConfigJson(raw, toolRegistry);
return { format: "automate", ...result };
}
if (format === "folderScanning") {
const result = parseFolderScanningConfig(raw, toolRegistry);
return { format: "folderScanning", ...result };
}View on GitHub (pinned to 9ef20dcab8)
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.
Example fix
// before parseAutomationFile(text, toolRegistry, 'automate'); // file is folder-scanning -> throws // after const detected = detectAutomationFormat(JSON.parse(text)); parseAutomationFile(text, toolRegistry, detected ?? undefined);
Defensive patterns
Strategy: validation
Validate before calling
const detected = detectAutomationFormat(JSON.parse(text.replace(/^\uFEFF/, '')));
if (expectedFormat && detected !== 'unknown' && detected !== expectedFormat) {
throw new Error(`File is ${detected}, not ${expectedFormat}. Switch the import type.`);
} Type guard
function formatMatches(text: string, expected: 'automate' | 'folderScanning'): boolean {
const d = detectAutomationFormat(JSON.parse(text.replace(/^\uFEFF/, '')));
return d === 'unknown' || d === expected;
} Prevention
- 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.
When it happens
Trigger: The caller asked for 'automate' but the file has a pipeline[] (folder-scanning), or asked for 'folderScanning' but the file has operations[] (automate).
Common situations: 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.
Related errors
- Invalid folder scanning config: expected JSON object
- Invalid folder scanning config: missing 'pipeline' array
- Invalid folder scanning config: pipeline[${index}] is not an
- Invalid folder scanning config: pipeline[${index}].operation
- Invalid automation config: expected JSON object
AI-assisted analysis of Stirling-Tools/Stirling-PDF@9ef20dcab8 (2026-08-13).
Data as JSON: /api/errors/07dfd2273486585f.
Report an issue: GitHub.