{"record":{"id":"b27bfc66129ae384","repo":"Stirling-Tools/Stirling-PDF","slug":"failed-to-process-all-files-failedfiles-join","errorCode":null,"errorMessage":"Failed to process all files: ${failedFiles.join(\", \")}","messagePattern":"Failed to process all files: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"frontend/editor/src/core/hooks/tools/shared/useToolApiCalls.ts","lineNumber":122,"sourceCode":"            produced: responseFiles.length,\n          });\n        } catch (error) {\n          if (axios.isCancel(error)) {\n            throw new Error(\"Operation was cancelled\", { cause: error });\n          }\n          console.error(\"[processFiles] Failed\", { name: file.name, error });\n          failedFiles.push(file.name);\n          // mark errored file so UI can highlight\n          try {\n            markFileError?.(file.fileId);\n          } catch (e) {\n            console.debug(\"markFileError\", e);\n          }\n        }\n      }\n\n      if (failedFiles.length > 0 && processedFiles.length === 0) {\n        throw new Error(\n          `Failed to process all files: ${failedFiles.join(\", \")}`,\n        );\n      }\n\n      if (failedFiles.length > 0) {\n        onStatus(\n          `Processed ${processedFiles.length}/${total} files. Failed: ${failedFiles.join(\", \")}`,\n        );\n      } else {\n        onStatus(\n          `Successfully processed ${processedFiles.length} file${processedFiles.length === 1 ? \"\" : \"s\"}`,\n        );\n      }\n\n      console.debug(\"[processFiles] Completed batch\", {\n        total,\n        successes: successSourceIds.length,\n        outputs: processedFiles.length,","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/Stirling-Tools/Stirling-PDF/blob/9ef20dcab80b85041912f045e17a6aea1d08f969/frontend/editor/src/core/hooks/tools/shared/useToolApiCalls.ts#L104-L140","documentation":"Thrown at the end of the per-file processing loop when every file failed (failedFiles.length > 0) and none succeeded (processedFiles.length === 0). It is the all-failed aggregate — partial failures (some succeeded) are reported via onStatus instead of throwing. Each per-file failure was already captured into failedFiles and markFileError was called.","triggerScenarios":"All files in a batch hit the same backend error (e.g. endpoint down, all files corrupt, all exceed size limit); a shared misconfiguration (wrong endpoint, missing auth) makes every POST fail; the backend is unreachable for the whole batch.","commonSituations":"Backend down/unreachable; all selected files share an unsupported property (encrypted, wrong format); auth token expired mid-session so every request 401s.","solutions":["Inspect the per-file console.error entries above this throw — they hold the actual HTTP errors for each file.","If all files share a cause (format, size, auth), fix the shared precondition rather than retrying per file.","Check backend reachability and the network panel for the common status code.","For auth failures, refresh the token/session and retry the batch."],"exampleFix":"// before\nif (failedFiles.length > 0 && processedFiles.length === 0) {\n  throw new Error(`Failed to process all files: ${failedFiles.join(\", \")}`);\n}\n\n// after — include the common failure reason if all files errored identically\nif (failedFiles.length > 0 && processedFiles.length === 0) {\n  throw new Error(`Failed to process all files: ${failedFiles.join(\", \")}${lastError ? ` (${lastError})` : \"\"}`);\n}","handlingStrategy":"try-catch","validationCode":"// Pre-flight one file to detect a shared failure (auth, endpoint down)\ntry {\n  await apiClient.head(endpoint); // or a tiny probe\n} catch {\n  // surface a shared-cause message before running the whole batch\n}","typeGuard":null,"tryCatchPattern":"try {\n  await processFiles(...);\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith(\"Failed to process all files:\")) {\n    toast.error(e.message);\n    // inspect console.error entries for the common per-file HTTP status\n  } else throw e;\n}","preventionTips":["Inspect the per-file console.error entries — they hold the actual HTTP errors.","Fix shared preconditions (auth, reachability, file format) before retrying.","Refresh the session token if every request 401s."],"tags":["batch-processing","axios","aggregate-error"],"backgroundTag":null,"analyzedSha":"9ef20dcab80b85041912f045e17a6aea1d08f969","analyzedAt":"2026-08-13T22:11:39.827Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}