jackwener/OpenCLI · error · ArgumentError

chatgpt project-file-add requires at least one file path

Error message

chatgpt project-file-add requires at least one file path

What it means

ArgumentError thrown by `chatgpt project-file-add` when `parseFilePaths(kwargs.file)` yields an empty list — i.e. no `--file` path was supplied (or all supplied paths were empty). The command needs at least one file to upload to project knowledge.

Source

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

export const projectFileAddCommand = cli({
    site: 'chatgpt',
    name: 'project-file-add',
    access: 'write',
    description: 'Upload files to a ChatGPT project as project knowledge (not just conversation attachments)',
    domain: CHATGPT_DOMAIN,
    strategy: Strategy.COOKIE,
    browser: true,
    siteSession: 'persistent',
    navigateBefore: false,
    args: [
        { name: 'file', positional: true, required: true, help: 'Local file path(s) to upload; comma-separated paths are supported' },
        { 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(

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass at least one file path: `opencli chatgpt project-file-add report.pdf --id 12345678`.
  2. Check shell quoting / variable expansion so --file receives a non-empty value.
  3. Repeat --file for each path if multiple files are needed.

Example fix

// before
opencli chatgpt project-file-add --id 12345678
// after
opencli chatgpt project-file-add report.pdf --id 12345678
Defensive patterns

Strategy: validation

Validate before calling

const files = process.argv.filter(a => !a.startsWith('--'));
if (!files.length) {
  console.error('Usage: opencli chatgpt project-file-add <file...> --id <projectId>');
  process.exit(2);
}

Type guard

function hasFilePaths(v) { return Array.isArray(v) && v.length > 0 && v.every(p => typeof p === 'string' && p.trim() !== ''); }

Try / catch

try {
  await run(['chatgpt', 'project-file-add', ...files, '--id', id]);
} catch (err) {
  if (String(err.message).includes('requires at least one file path')) {
    console.error('Provide at least one file, e.g. report.pdf');
  }
}

Prevention

When it happens

Trigger: Invoking `opencli chatgpt project-file-add --id <id>` without `--file`, or with a value that parses to zero paths.

Common situations: Forgetting the --file flag; quoting mistakes so the argument is empty; scripts passing an empty variable; passing a directory instead of file paths that the parser drops.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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