{"record":{"id":"2cc739a943613bba","repo":"jackwener/OpenCLI","slug":"invalid-user-id-userid","errorCode":null,"errorMessage":"Invalid user ID: ${userId}","messagePattern":"Invalid user ID: (.+?)","errorType":"validation","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/pixiv/illusts.js","lineNumber":27,"sourceCode":"import { CommandExecutionError } from '@jackwener/opencli/errors';\nimport { pixivFetch, BATCH_SIZE } from './utils.js';\ncli({\n    site: 'pixiv',\n    name: 'illusts',\n    access: 'read',\n    description: \"List a Pixiv artist's illustrations\",\n    domain: 'www.pixiv.net',\n    strategy: Strategy.COOKIE,\n    args: [\n        { name: 'user-id', positional: true, required: true, help: 'Pixiv user ID' },\n        { name: 'limit', type: 'int', default: 20, help: 'Number of results' },\n    ],\n    columns: ['rank', 'title', 'illust_id', 'pages', 'bookmarks', 'tags', 'created', 'url'],\n    func: async (page, kwargs) => {\n        const userId = String(kwargs['user-id'] ?? '');\n        const limit = Number(kwargs.limit) || 20;\n        if (!/^\\d+$/.test(userId)) {\n            throw new CommandExecutionError(`Invalid user ID: ${userId}`);\n        }\n        // Step 1: get all illust IDs\n        const profileBody = await pixivFetch(page, `/ajax/user/${userId}/profile/all`, {\n            notFoundMsg: `User not found: ${userId}`,\n        });\n        const allIds = Object.keys(profileBody?.illusts || {})\n            .sort((a, b) => Number(b) - Number(a))\n            .slice(0, limit);\n        if (allIds.length === 0)\n            return [];\n        // Step 2: batch fetch details (Pixiv supports up to ~48 IDs per request)\n        const allWorks = {};\n        for (let offset = 0; offset < allIds.length; offset += BATCH_SIZE) {\n            const batch = allIds.slice(offset, offset + BATCH_SIZE);\n            const idsParam = batch.map(id => `ids[]=${id}`).join('&');\n            // pixivFetch navigates on each call; for subsequent batches we re-navigate,\n            // which is fine — the cookie is already attached.\n            const detailBody = await pixivFetch(page, `/ajax/user/${userId}/profile/illusts?${idsParam}&work_category=illustManga&is_first_page=${offset === 0 ? 1 : 0}`);","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/pixiv/illusts.js#L9-L45","documentation":"Thrown by the pixiv illusts command when the --user-id argument is not a digit-only string. Like the illust ID check, it validates with /^\\d+$/ before calling /ajax/user/{id}/profile/all.","triggerScenarios":"Passing a pixiv username/screen name instead of the numeric user ID, an empty value, or an ID copied with extra text (e.g. from a profile URL query string).","commonSituations":"Confusing the pixiv display name or URL alias (e.g. 'someuser') with the internal numeric user ID; automation passing an unset variable.","solutions":["Use the numeric pixiv user ID (visible in the profile URL as /users/12345), not the account name","Extract digits from a profile URL: https://www.pixiv.net/users/12345 -> 12345","Print the value being passed to confirm it is non-empty and digit-only","Fix the upstream data source that supplies the user ID"],"exampleFix":"// before\npixiv illusts --user-id someuser\n// after\npixiv illusts --user-id 12345","handlingStrategy":"validation","validationCode":"const raw = String(kwargs['user-id'] ?? '');\nif (!/^\\d+$/.test(raw)) throw new Error(`--user-id must be numeric, got: ${raw}`);","typeGuard":"const isPixivUserId = (v) => /^\\d+$/.test(String(v).trim());","tryCatchPattern":"try {\n  await pixivIllusts({ userId });\n} catch (e) {\n  if (String(e.message).startsWith('Invalid user ID')) {\n    console.error('Use the numeric ID from /users/<id>, not the account name');\n  } else throw e;\n}","preventionTips":["Resolve profile URLs like /users/12345 to the numeric ID","Never pass pixiv screen names as user-id","Validate IDs digit-only before invoking","Check upstream variables for empty values"],"tags":["validation","cli","input"],"backgroundTag":"invalid-id-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}