{"record":{"id":"e5f5a60a95f618c0","repo":"jackwener/OpenCLI","slug":"could-not-find-user-username","errorCode":null,"errorMessage":"Could not find user @${username}","messagePattern":"Could not find user @(.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/twitter/likes.js","lineNumber":269,"sourceCode":"        const likesQueryId = await resolveTwitterQueryId(page, 'Likes', LIKES_QUERY_ID);\n        const userByScreenNameQueryId = await resolveTwitterQueryId(page, 'UserByScreenName', USER_BY_SCREEN_NAME_QUERY_ID);\n        const headers = JSON.stringify({\n            'Authorization': `Bearer ${decodeURIComponent(TWITTER_BEARER_TOKEN)}`,\n            'X-Csrf-Token': ct0,\n            'X-Twitter-Auth-Type': 'OAuth2Session',\n            'X-Twitter-Active-User': 'yes',\n        });\n        // Get userId from screen_name\n        const userId = unwrapBrowserResult(await page.evaluate(`async () => {\n      const screenName = ${JSON.stringify(username)};\n      const url = ${JSON.stringify(buildUserByScreenNameQueryUrl(userByScreenNameQueryId, username))};\n      const resp = await fetch(url, { headers: ${headers}, credentials: 'include' });\n      if (!resp.ok) return null;\n      const d = await resp.json();\n      return d.data?.user?.result?.rest_id || null;\n    }`));\n        if (!userId) {\n            throw new CommandExecutionError(`Could not find user @${username}`);\n        }\n        const resumed = fetchAll ? readResumeFile(resumeFile, {\n            source: 'likes',\n            username,\n            outputFile: useOutputFile ? outputFile : null,\n        }) : null;\n        if (useOutputFile && resumed && resumed.count > 0 && !fs.existsSync(outputFile)) {\n            throw new CommandExecutionError(`Twitter likes output file is missing for resume state: ${outputFile}`);\n        }\n        if (useOutputFile && !resumed && fs.existsSync(outputFile)) {\n            throw new ArgumentError(`Refusing to overwrite existing Twitter likes output file: ${outputFile}`);\n        }\n        const allTweets = useOutputFile ? [] : (resumed?.tweets ? [...resumed.tweets] : []);\n        const jsonlState = useOutputFile ? loadJsonlArchiveState(outputFile) : null;\n        const seen = useOutputFile\n            ? jsonlState.seen\n            : new Set(allTweets.map((tweet) => tweet?.id).filter(Boolean));\n        if (useOutputFile && resumed && jsonlState.count !== resumed.count) {","sourceCodeStart":251,"sourceCodeEnd":287,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/twitter/likes.js#L251-L287","documentation":"CommandExecutionError thrown when the UserByScreenName GraphQL lookup returns no user rest_id for the requested handle. The library resolves the handle to a numeric user ID before querying Likes; a missing rest_id means the account does not exist, is suspended, or is not resolvable with the current session.","triggerScenarios":"fetchUserByScreenName (in-page fetch of the UserByScreenName GraphQL endpoint) returns resp.ok but d.data.user.result.rest_id is falsy, so clis/twitter/likes.js:269 throws `Could not find user @${username}`.","commonSituations":"Typo in the @username passed on the command line; the account was renamed or deleted; the account is suspended/locked; running against a handle whose visibility changed (protected/deactivated).","solutions":["Check the @username for typos and confirm the account exists by opening https://x.com/<username>.","If the account was renamed, use the current handle.","Re-authenticate: a stale session can make the lookup return an empty user result.","If the account is suspended or deactivated, the error is expected; no fix exists."],"exampleFix":"// before\n$ cli twitter likes @joohn_doe\n// after\n$ cli twitter likes @john_doe   // corrected handle","handlingStrategy":"validation","validationCode":"const handle = username.replace(/^@/, '');\nif (!/^[A-Za-z0-9_]{1,15}$/.test(handle)) {\n  throw new Error(`Invalid Twitter handle: ${username}`);\n}","typeGuard":"function isValidHandle(u) { return typeof u === 'string' && /^@?[A-Za-z0-9_]{1,15}$/.test(u); }","tryCatchPattern":"try {\n  await cli.twitter.likes({ username });\n} catch (e) {\n  if (/Could not find user @/.test(e.message)) {\n    console.error(`Handle '${username}' not found; verify it exists at https://x.com/${username.replace('@','')}`);\n  } else throw e;\n}","preventionTips":["Verify the handle resolves on x.com before scripting it","Strip stray characters like @ or whitespace from CLI args","Handle renames by storing user IDs, not just handles","Treat suspended/deactivated accounts as expected failures"],"tags":["api","not-found","twitter"],"backgroundTag":"user-not-found","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}