{"record":{"id":"097636c438921724","repo":"Stirling-Tools/Stirling-PDF","slug":"automation-step-stepindex-1-failed-error","errorCode":null,"errorMessage":"Automation step ${stepIndex + 1} failed: ${error}","messagePattern":"Automation step (.+?) failed: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"frontend/editor/src/core/hooks/tools/automate/useAutomateOperation.ts","lineNumber":43,"sourceCode":"      // Execute the automation sequence and return the final results\n      const finalResults = await executeAutomationSequence(\n        params.automationConfig!,\n        files,\n        toolRegistry,\n        (stepIndex: number, operationName: string) => {\n          console.log(`Step ${stepIndex + 1} started: ${operationName}`);\n          params.onStepStart?.(stepIndex, operationName);\n        },\n        (stepIndex: number, resultFiles: File[]) => {\n          console.log(\n            `Step ${stepIndex + 1} completed with ${resultFiles.length} files`,\n          );\n          params.onStepComplete?.(stepIndex, resultFiles);\n        },\n        (stepIndex: number, error: string) => {\n          console.error(`Step ${stepIndex + 1} failed:`, error);\n          params.onStepError?.(stepIndex, error);\n          throw new Error(`Automation step ${stepIndex + 1} failed: ${error}`);\n        },\n      );\n\n      console.log(\n        `✅ Automation completed, returning ${finalResults.length} files`,\n      );\n      return {\n        files: finalResults,\n        consumedAllInputs: true,\n      };\n    },\n    [toolRegistry],\n  );\n\n  return useToolOperation<AutomateParameters>(\n    defineCustomTool({\n      operationType: \"automate\",\n      customProcessor,","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/Stirling-Tools/Stirling-PDF/blob/9ef20dcab80b85041912f045e17a6aea1d08f969/frontend/editor/src/core/hooks/tools/automate/useAutomateOperation.ts#L25-L61","documentation":"Thrown from the per-step error callback passed to `executeAutomationSequence`. When any step in the automation chain fails, the executor invokes onStepError with the index and error string; this callback rethrows so the overall automation aborts and surfaces which step broke. The error string is whatever the failed step (a downstream tool operation) reported.","triggerScenarios":"A downstream tool in the chain threw (e.g. convert got 'Unsupported conversion format', compress hit a network error, split returned no files); a step received a file format it cannot handle; a step's API call failed (5xx / timeout); a step produced zero output files and the executor treats that as failure.","commonSituations":"Multi-step automations where an earlier step's output is incompatible with a later step; backend intermittently failing one endpoint in the chain; a step referencing a tool not present in the registry.","solutions":["Inspect the originating step's own error (it is carried in the `${error}` fragment) and fix the root cause there.","Make automation steps resilient: validate each step's output before passing it downstream.","Add per-step retry with backoff for transient (network/5xx) errors so a single flaky step does not abort the whole run.","Log the full AutomationStep + params at onStepError for debugging which configuration is at fault."],"exampleFix":"// before\n(stepIndex: number, error: string) => {\n  console.error(`Step ${stepIndex + 1} failed:`, error);\n  params.onStepError?.(stepIndex, error);\n  throw new Error(`Automation step ${stepIndex + 1} failed: ${error}`);\n},\n\n// after — keep cause and step identity for richer debugging\n(stepIndex: number, error: string) => {\n  console.error(`Step ${stepIndex + 1} failed:`, error);\n  params.onStepError?.(stepIndex, error);\n  throw new Error(`Automation step ${stepIndex + 1} failed: ${error}`, { cause: error });\n},","handlingStrategy":"try-catch","validationCode":"// Validate each step's config + output compatibility before running the chain\nfor (const step of params.automationConfig.steps) {\n  if (!toolRegistry[step.operation]) {\n    // surface 'step N references unknown operation' before running\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  await runAutomation();\n} catch (e) {\n  const m = e instanceof Error && e.message.match(/Automation step (\\d+) failed: (.+)/);\n  if (m) {\n    const [, step, reason] = m;\n    toast.error(`Step ${step} failed: ${reason}`);\n  } else throw e;\n}","preventionTips":["Validate each step references a registered operation before execution.","Add per-step retry/backoff for transient errors so one flaky step does not abort the run.","Log the full AutomationStep params at onStepError to identify the misconfigured step."],"tags":["automation","tool-pipeline","error-chaining"],"backgroundTag":null,"analyzedSha":"9ef20dcab80b85041912f045e17a6aea1d08f969","analyzedAt":"2026-08-13T22:11:39.827Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}