{"record":{"id":"faf46f132d84160a","repo":"danny-avila/LibreChat","slug":"error-uploading-code-environment-file-error-mes","errorCode":null,"errorMessage":"Error uploading code environment file: ${error.message}","messagePattern":"Error uploading code environment file: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"api/server/services/Files/Code/crud.js","lineNumber":186,"sourceCode":"      timeout: 120000,\n      maxContentLength: MAX_FILE_SIZE,\n      maxBodyLength: MAX_FILE_SIZE,\n    };\n\n    const response = await axios.post(`${baseURL}/upload`, form, options);\n\n    /** @type {{ message: string; storage_session_id: string; files: Array<{ fileId: string; filename: string }> }} */\n    const result = response.data;\n    if (result.message !== 'success') {\n      throw new Error(`Error uploading file: ${result.message}`);\n    }\n\n    return {\n      storage_session_id: result.storage_session_id,\n      file_id: result.files[0].fileId,\n    };\n  } catch (error) {\n    throw new Error(\n      logAxiosError({\n        message: `Error uploading code environment file: ${error.message}`,\n        error,\n      }),\n    );\n  }\n}\n\n/**\n * Uploads multiple files to the code execution environment in a single request.\n * Uses the /upload/batch endpoint which shares one session_id across all files.\n *\n * `kind`/`id`/`version?` carry the resource identity for codeapi's sessionKey\n * derivation — see `uploadCodeEnvFile` for the full motivation.\n *\n * @param {object} params\n * @param {import('express').Request & { user: { id: string } }} params.req - The request object.\n * @param {Array<{ stream: NodeJS.ReadableStream; filename: string }>} params.files - Files to upload.","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/danny-avila/LibreChat/blob/5ff282f9006c436e561de1afd39a481bea1ef0d8/api/server/services/Files/Code/crud.js#L168-L204","documentation":"Thrown by the single-file upload catch block (Code/crud.js) wrapping any axios-level failure from POST /upload via logAxiosError. This covers transport/size/timeout failures distinct from the application-layer rejection in error 86.","triggerScenarios":"axios.post to /upload throws: file exceeds maxContentLength/maxBodyLength (MAX_FILE_SIZE = 150MB), request exceeds the 120s timeout, connection refused, TLS error, or auth header minting threw inside the try.","commonSituations":"Uploading a file larger than 150MB; slow link triggering the 120s timeout; code server down or misconfigured baseURL; getCodeApiAuthHeaders threw before the request.","solutions":["Confirm the file is under MAX_FILE_SIZE (150MB) — compress or reject upstream if not.","Increase the 120000ms timeout for legitimately slow links, or move large uploads to a direct-to-storage path.","Verify the code server is reachable and getCodeBaseURL() is correct.","Read the logAxiosError diagnostics for the precise axios error code (ECONNABORTED, 413, etc.)."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Enforce size limit before the request\nconst MAX_FILE_SIZE = 150 * 1024 * 1024;\nif (fileBuffer.length > MAX_FILE_SIZE) {\n  throw new Error(`File exceeds ${MAX_FILE_SIZE} bytes`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await uploadCodeEnvFile(params);\n} catch (err) {\n  if (/timeout|ECONNABORTED/i.test(err.message)) {\n    await sleep(1000);\n    return uploadCodeEnvFile(params); // single retry\n  }\n  if (/maxContentLength|413/i.test(err.message)) {\n    return res.status(413).json({ message: 'File too large for code environment' });\n  }\n  throw err;\n}","preventionTips":["Reject files over MAX_FILE_SIZE (150MB) before issuing the upload.","Retry once on timeout/ECONNABORTED; do not retry 413.","Keep the 120s timeout aligned with the slowest legitimate link."],"tags":["code-env","upload","limits","timeout","axios"],"backgroundTag":null,"analyzedSha":"5ff282f9006c436e561de1afd39a481bea1ef0d8","analyzedAt":"2026-08-12T21:38:08.145Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}