danny-avila/LibreChat · error

Error uploading code environment file: ${error.message}

Error message

Error uploading code environment file: ${error.message}

What it means

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.

Source

Thrown at api/server/services/Files/Code/crud.js:186

      timeout: 120000,
      maxContentLength: MAX_FILE_SIZE,
      maxBodyLength: MAX_FILE_SIZE,
    };

    const response = await axios.post(`${baseURL}/upload`, form, options);

    /** @type {{ message: string; storage_session_id: string; files: Array<{ fileId: string; filename: string }> }} */
    const result = response.data;
    if (result.message !== 'success') {
      throw new Error(`Error uploading file: ${result.message}`);
    }

    return {
      storage_session_id: result.storage_session_id,
      file_id: result.files[0].fileId,
    };
  } catch (error) {
    throw new Error(
      logAxiosError({
        message: `Error uploading code environment file: ${error.message}`,
        error,
      }),
    );
  }
}

/**
 * Uploads multiple files to the code execution environment in a single request.
 * Uses the /upload/batch endpoint which shares one session_id across all files.
 *
 * `kind`/`id`/`version?` carry the resource identity for codeapi's sessionKey
 * derivation — see `uploadCodeEnvFile` for the full motivation.
 *
 * @param {object} params
 * @param {import('express').Request & { user: { id: string } }} params.req - The request object.
 * @param {Array<{ stream: NodeJS.ReadableStream; filename: string }>} params.files - Files to upload.

View on GitHub (pinned to 5ff282f900)

Solutions

  1. Confirm the file is under MAX_FILE_SIZE (150MB) — compress or reject upstream if not.
  2. Increase the 120000ms timeout for legitimately slow links, or move large uploads to a direct-to-storage path.
  3. Verify the code server is reachable and getCodeBaseURL() is correct.
  4. Read the logAxiosError diagnostics for the precise axios error code (ECONNABORTED, 413, etc.).
Defensive patterns

Strategy: retry

Validate before calling

// Enforce size limit before the request
const MAX_FILE_SIZE = 150 * 1024 * 1024;
if (fileBuffer.length > MAX_FILE_SIZE) {
  throw new Error(`File exceeds ${MAX_FILE_SIZE} bytes`);
}

Try / catch

try {
  await uploadCodeEnvFile(params);
} catch (err) {
  if (/timeout|ECONNABORTED/i.test(err.message)) {
    await sleep(1000);
    return uploadCodeEnvFile(params); // single retry
  }
  if (/maxContentLength|413/i.test(err.message)) {
    return res.status(413).json({ message: 'File too large for code environment' });
  }
  throw err;
}

Prevention

When it happens

Trigger: 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.

Common situations: Uploading a file larger than 150MB; slow link triggering the 120s timeout; code server down or misconfigured baseURL; getCodeApiAuthHeaders threw before the request.

Related errors


AI-assisted analysis of danny-avila/LibreChat@5ff282f900 (2026-08-12). Data as JSON: /api/errors/faf46f132d84160a. Report an issue: GitHub.