jackwener/OpenCLI · error · ArgumentError

Either --to or --to-fid is required

Error message

Either --to or --to-fid is required

What it means

Thrown by clis/quark/save.js when neither --to (target folder path) nor --to-fid (target folder id) is provided for a share-save operation. The command needs exactly one destination, so it raises ArgumentError before contacting the API.

Source

Thrown at clis/quark/save.js:41

    defaultFormat: 'json',
    args: [
        { name: 'url', required: true, positional: true, help: 'Quark share URL or pwd_id' },
        { name: 'to', default: '', help: 'Destination folder path' },
        { name: 'to-fid', default: '', help: 'Destination folder ID (overrides --to)' },
        { name: 'fids', default: '', help: 'File IDs to save (comma-separated, from share-tree). Omit to save all.' },
        { name: 'stoken', default: '', help: 'Share token (from share-tree output, required with --fids)' },
        { name: 'passcode', default: '', help: 'Share passcode (if required)' },
        { name: 'timeout', type: 'int', required: false, default: 120, help: 'Max seconds for the overall command (default: 120)' },
    ],
    func: async (page, kwargs) => {
        const url = kwargs.url;
        const to = kwargs.to;
        const toFid = kwargs['to-fid'];
        const fids = kwargs.fids;
        const stokenArg = kwargs.stoken;
        const passcode = kwargs.passcode;
        if (!to && !toFid)
            throw new ArgumentError('Either --to or --to-fid is required');
        if (to && toFid)
            throw new ArgumentError('Cannot use both --to and --to-fid');
        const pwdId = extractPwdId(url);
        const saveAll = !fids;
        let stoken;
        let fidList;
        if (saveAll) {
            stoken = stokenArg || await getToken(page, pwdId, passcode);
            fidList = [];
        }
        else {
            if (!stokenArg)
                throw new ArgumentError('--stoken is required when using --fids');
            stoken = stokenArg;
            fidList = [...new Set(fids.split(',').map(id => id.trim()).filter(Boolean))];
        }
        const targetFid = toFid || await findFolder(page, to);
        const taskId = await saveShare(page, pwdId, stoken, fidList, targetFid, saveAll);

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Add a destination: --to /my/folder or --to-fid <folder_fid>.
  2. If you have the folder id from a prior listing, prefer --to-fid to avoid path lookup.
  3. In scripts, default the destination variable to a known folder before invoking.

Example fix

// before
quark save https://pan.quark.cn/s/abc123
// after
quark save https://pan.quark.cn/s/abc123 --to /saved
Defensive patterns

Strategy: validation

Validate before calling

if (!process.env.TO && !process.env.TO_FID) {
  throw new Error('save requires --to or --to-fid');
}

Prevention

When it happens

Trigger: Running the save command with only the share URL (and optional --fids) but omitting both destination flags; forgetting that the destination is mandatory even when saving all files.

Common situations: Copy-pasting an example command without the destination flags; assuming files save to the drive root by default; scripts where the destination variable is unset.

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/7f6da267d1640643. Report an issue: GitHub.