{"record":{"id":"151e2668901e98dd","repo":"jackwener/OpenCLI","slug":"xiaohongshu-follow-invalid-profile-url","errorCode":null,"errorMessage":"xiaohongshu/follow: invalid profile URL","messagePattern":"xiaohongshu/follow: invalid profile URL","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/xiaohongshu/follow.js","lineNumber":47,"sourceCode":"    return host === 'xiaohongshu.com' || host.endsWith('.xiaohongshu.com');\n}\n\nfunction requireActionResult(payload, context) {\n    const inner = unwrapEvaluateResult(payload);\n    if (!inner || typeof inner !== 'object' || Array.isArray(inner) || typeof inner.ok !== 'boolean') {\n        throw new CommandExecutionError(`xiaohongshu/follow: malformed ${context} payload`);\n    }\n    return inner;\n}\n\nfunction assertUserId(raw) {\n    const input = String(raw ?? '').trim();\n    if (/^https?:\\/\\//i.test(input)) {\n        let parsed;\n        try {\n            parsed = new URL(input);\n        } catch {\n            throw new ArgumentError('xiaohongshu/follow: invalid profile URL');\n        }\n        if (parsed.protocol !== 'https:' || !isXiaohongshuHost(parsed.hostname)) {\n            throw new ArgumentError('xiaohongshu/follow: profile URL must be an exact https://*.xiaohongshu.com URL');\n        }\n        const match = parsed.pathname.match(/^\\/user\\/profile\\/([a-zA-Z0-9]{8,32})\\/?$/);\n        if (!match) {\n            throw new ArgumentError('xiaohongshu/follow: profile URL must be /user/profile/<userId>');\n        }\n        return match[1];\n    }\n    const userId = normalizeXhsUserId(raw);\n    if (!userId || !USER_ID_RE.test(userId)) {\n        throw new ArgumentError(\n            'xiaohongshu/follow: user-id must be a Xiaohongshu user ID (e.g. 5d8f88dc0000000001005d3a) or full profile URL',\n        );\n    }\n    return userId;\n}","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/xiaohongshu/follow.js#L29-L65","documentation":"assertUserId accepts either a raw user ID or a full profile URL. If the input looks like a URL (starts with http:// or https://) but new URL() cannot parse it, an ArgumentError (exit code 2, usage error) is thrown. This means the argument is syntactically not a valid URL at all.","triggerScenarios":"Passing something like 'https//www.xiaohongshu.com/user/profile/5d8f...' (missing colon), 'https:// user profile', or a URL with stray spaces/newlines to the --user-id option of the xiaohongshu follow command.","commonSituations":"Copy-paste truncation from a terminal (protocol mangled); shell quoting stripping characters; manually typing the URL with typos; pasting markdown-wrapped URLs with trailing punctuation.","solutions":["Fix the URL syntax — it must be a valid absolute URL like https://www.xiaohongshu.com/user/profile/<userId>.","Alternatively pass just the raw 24-char user ID (e.g. 5d8f88dc0000000001005d3a) instead of a URL.","Trim whitespace and re-copy the URL from the browser address bar without markdown or quotes."],"exampleFix":"// before\nopencli xiaohongshu follow --user-id 'https//www.xiaohongshu.com/user/profile/5d8f88dc0000000001005d3a'\n// after\nopencli xiaohongshu follow --user-id 'https://www.xiaohongshu.com/user/profile/5d8f88dc0000000001005d3a'","handlingStrategy":"validation","validationCode":"function isValidProfileUrl(raw) {\n  const s = String(raw ?? '').trim();\n  if (!/^https?:\\/\\//i.test(s)) return true; // treated as user id\n  try { new URL(s); return true; } catch { return false; }\n}","typeGuard":null,"tryCatchPattern":"try {\n  await opencliFollow(userIdArg);\n} catch (err) {\n  if (err.code === 'ARGUMENT') {\n    console.error(`Bad --user-id: ${userIdArg}. Use a user ID or full https URL.`);\n    process.exitCode = 2;\n  } else throw err;\n}","preventionTips":["Copy URLs directly from the browser address bar","Trim whitespace from CLI arguments before passing","Prefer passing the raw 24-char user ID over URLs","Quote URLs in shell to avoid mangling"],"tags":["argument-validation","url-parsing","cli-usage","xiaohongshu"],"backgroundTag":"invalid-url-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}