jackwener/OpenCLI · warning · ArgumentError

Invalid illustration ID: ${id}

Error message

Invalid illustration ID: ${id}

What it means

The pixiv detail command reads kwargs.id, coerces it to a string, and requires it to be purely digits before constructing the /ajax/illust/<id> URL. This ArgumentError is thrown before any network request when the supplied ID is empty, contains non-numeric characters (URLs, "artwork123", whitespace), or is missing entirely.

Source

Thrown at clis/pixiv/detail.js:45

        { name: 'id', required: true, positional: true, help: 'Illustration ID' },
    ],
    columns: [
        'illust_id',
        'title',
        'author',
        'type',
        'pages',
        'bookmarks',
        'likes',
        'views',
        'tags',
        'created',
        'url',
    ],
    func: async (page, kwargs) => {
        const id = String(kwargs.id ?? '');
        if (!/^\d+$/.test(id)) {
            throw new ArgumentError(`Invalid illustration ID: ${id}`, 'Example: opencli pixiv detail 123456');
        }
        const body = await pixivFetch(page, `/ajax/illust/${id}`, {
            notFoundMsg: `Illustration not found: ${id}`,
        });
        const b = requireIllustBody(body, id);
        return [{
            illust_id: b.illustId,
            title: b.illustTitle,
            author: b.userName,
            user_id: b.userId,
            type: b.illustType === 0 ? 'illust' : b.illustType === 1 ? 'manga' : b.illustType === 2 ? 'ugoira' : String(b.illustType),
            pages: b.pageCount,
            bookmarks: b.bookmarkCount,
            likes: b.likeCount,
            views: b.viewCount,
            tags: (b.tags?.tags || []).map(t => t.tag).join(', '),
            created: b.createDate?.split('T')[0] || '',
            url: `https://www.pixiv.net/artworks/${b.illustId}`,

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass only the numeric artwork ID, e.g. `opencli pixiv detail 123456`.
  2. Extract the number from a pasted URL first (the digits after /artworks/ or ?illust_id=).
  3. Strip non-digit suffixes like page indicators (`_1`) or whitespace before invoking.
  4. If programmatically calling, validate with /^\d+$/.test(String(id)) before invoking the command.
  5. Use the example from the error message: `opencli pixiv detail 123456`.

Example fix

// before
opencli pixiv detail https://www.pixiv.net/artworks/987654
// after
opencli pixiv detail 987654
Defensive patterns

Strategy: validation

Validate before calling

function normalizeIllustId(raw) {
  const m = String(raw ?? '').match(/(\d+)(?:_\d+)?$/); // accepts URLs, page suffixes
  const id = m ? m[1] : String(raw ?? '').trim();
  if (!/^\d+$/.test(id)) throw new Error(`Invalid illustration ID: ${raw}`);
  return id;
}
await cliDetail(page, { id: normalizeIllustId(input) });

Type guard

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

Try / catch

try {
  const rows = await pixivDetail(page, { id });
} catch (e) {
  if (e instanceof ArgumentError && e.message.startsWith('Invalid illustration ID')) {
    console.error('Provide a numeric Pixiv artwork ID, e.g. opencli pixiv detail 123456');
    process.exitCode = 2;
  } else throw e;
}

Prevention

When it happens

Trigger: Running `opencli pixiv detail` with no id; passing a full Pixiv URL like https://www.pixiv.net/artworks/123456; passing "12345678_1" (page suffix) or a non-numeric slug; passing a novel ID format the regex rejects.

Common situations: User pastes the whole artwork URL instead of the numeric ID; shell quoting strips input leaving an empty string; copy includes trailing punctuation or a page suffix like `_2`; confusion between illust IDs and user IDs.

Related errors


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