jackwener/OpenCLI · error · CommandExecutionError

Failed to upload file to ChatGPT project knowledge

Error message

Failed to upload file to ChatGPT project knowledge: ${err instanceof Error ? err.message : String(err)}

What it means

CommandExecutionError wrapping any error raised by `uploadChatGPTProjectFiles` — navigation failures, selector timeouts, unexpected DOM, or page errors during upload. The original error message is appended to the message.

Solutions

  1. Read the wrapped message for the root cause and fix that underlying issue first.
  2. Confirm you have a logged-in ChatGPT session before running the command.
  3. Check network/proxy connectivity to chatgpt.com.
  4. Retry; if it persists, update the CLI's upload automation to the current ChatGPT UI.
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-checks before upload
const files = filePaths.filter(p => fs.existsSync(p));
if (!files.length) throw new Error('No valid local files to upload');
if (!/^\d+$|^\/g\/g-p-\d+/.test(projectIdArg)) throw new Error('Invalid project id');

Type guard

function isUploadResult(u) { return u !== null && typeof u === 'object'; }

Try / catch

try {
  await run(['chatgpt', 'project-file-add', ...files, '--id', id]);
} catch (err) {
  const msg = String(err.message);
  if (msg.startsWith('Failed to upload file to ChatGPT project knowledge:')) {
    console.error('Root cause:', msg.split(': ').slice(1).join(': '));
  }
}

Prevention

When it happens

Trigger: The try/catch around `uploadChatGPTProjectFiles(page, projectId, filePaths)` catches any thrown error while uploading local files to a ChatGPT project's knowledge.

Common situations: Not logged into ChatGPT so the upload page redirected to login; proxy/network issues reaching ChatGPT; ChatGPT DOM changed so the upload flow's selectors fail; project page rejected the navigation.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/0e142ac3911741f9. Report an issue: GitHub.

Appendix: source

Thrown at clis/chatgpt/project-file-add.js:50

        { name: 'id', required: true, help: 'Project ID or /g/g-p-<id> URL' },
    ],
    columns: ['Status', 'File'],
    func: async (page, kwargs) => {
        const filePaths = parseFilePaths(kwargs.file);
        if (!filePaths.length) {
            throw new ArgumentError(
                'chatgpt project-file-add requires at least one file path',
                'Example: opencli chatgpt project-file-add report.pdf --id 12345678',
            );
        }

        const projectId = parseChatGPTProjectId(kwargs.id);

        let upload;
        try {
            upload = await uploadChatGPTProjectFiles(page, projectId, filePaths);
        } catch (err) {
            throw new CommandExecutionError(
                `Failed to upload file to ChatGPT project knowledge: ${err instanceof Error ? err.message : String(err)}`,
            );
        }

        if (upload?.inputError) {
            throw new ArgumentError(
                upload.reason || 'Invalid project file path',
                'Provide an existing local file path that ChatGPT project knowledge can upload.',
            );
        }

        if (!upload?.ok) {
            throw new CommandExecutionError(
                upload?.reason || 'Failed to upload file to ChatGPT project knowledge',
                `Open ${CHATGPT_URL}/g/g-p-${projectId} and verify the project accepts file uploads. If your browser needs a proxy, configure it outside this command.`,
            );
        }

View on GitHub (pinned to 49907e53dc)