jackwener/OpenCLI · error · ArgumentError

Invalid novel ID: ${id}

Error message

Invalid novel ID: ${id}

What it means

Before fetching, the command validates the novel ID against /^\d+$/ (digits only). Pixiv novel IDs are positive integers; anything else (letters, whitespace, hyphens, empty string, undefined coerced to '') throws ArgumentError. The second ArgumentError argument carries a usage hint with a valid example.

Source

Thrown at clis/pixiv/novel-download.js:25

  name: 'novel-download',
  access: 'read',
  description: 'Download Pixiv novel text as txt or markdown',
  domain: 'www.pixiv.net',
  strategy: Strategy.COOKIE,
  args: [
    { name: 'novel-id', positional: true, required: true, help: 'Novel ID' },
    { name: 'output', default: './pixiv-downloads/novels', help: 'Output directory' },
    { name: 'file-format', default: 'txt', help: 'Output file format: txt or md' },
    { name: 'execute', type: 'boolean', default: false, help: 'Actually write the local novel file' },
  ],
  columns: ['novel_id', 'title', 'format', 'status', 'path'],
  func: async (page, kwargs) => {
    if (kwargs.execute !== true) {
      throw new ArgumentError('Refusing to write a local Pixiv novel: pass --execute');
    }
    const id = String(kwargs['novel-id'] ?? '');
    if (!/^\d+$/.test(id)) {
      throw new ArgumentError(`Invalid novel ID: ${id}`, 'Example: opencli pixiv novel-download 10588915 --file-format txt');
    }
    const format = normalizeNovelFileFormat(kwargs['file-format'] ?? kwargs.format);
    const output = normalizePixivOutputRoot(kwargs.output, './pixiv-downloads/novels');
    const body = await fetchNovelForDownload(page, id);
    const destPath = writeNovelFile(body, output, format);
    return [{ novel_id: body.id, title: body.title, format, status: 'success', path: destPath }];
  },
});

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass only the numeric ID: `opencli pixiv novel-download 10588915 --execute --file-format txt`.
  2. If using a URL, extract the id query parameter first, e.g. `url.split('id=')[1]` or a shell regex.
  3. Check the variable feeding --novel-id is set and contains only digits (trim whitespace).

Example fix

// before
const id = 'https://www.pixiv.net/novel/show.php?id=10588915';
await cli.pixivNovelDownload({ 'novel-id': id });
// after
const id = new URL(url).searchParams.get('id'); // '10588915'
if (!/^\d+$/.test(id)) throw new Error('novel-id must be numeric');
await cli.pixivNovelDownload({ 'novel-id': id });
Defensive patterns

Strategy: validation

Validate before calling

const raw = String(args['novel-id'] ?? '').trim();
const id = raw.includes('id=') ? new URL(raw).searchParams.get('id') : raw;
if (!/^\d+$/.test(id)) {
  throw new Error(`Invalid novel ID: ${id} — use digits only, e.g. 10588915`);
}

Type guard

function isPixivNovelId(v) {
  return typeof v === 'string' && /^\d+$/.test(v.trim());
}

Try / catch

try {
  await cli.pixiv.novelDownload({ 'novel-id': id, execute: true });
} catch (e) {
  if (e instanceof ArgumentError && /Invalid novel ID/.test(e.message)) {
    console.error(`Bad novel ID '${id}': use only digits, e.g. 10588915`);
  } else throw e;
}

Prevention

When it happens

Trigger: Passing `--novel-id` with a non-numeric value (e.g. 'abc', '10588915a', ' 123'), omitting --novel-id entirely (id becomes ''), or a URL pasted instead of the raw ID.

Common situations: Pasting a full Pixiv novel URL like https://www.pixiv.net/novel/show.php?id=10588915 instead of just the number; shell variables that are empty or unset; typos or trailing punctuation copied from a page.

Related errors


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