{"record":{"id":"a4fe5a720b6583a1","repo":"jackwener/OpenCLI","slug":"could-not-find-user-targetuser","errorCode":null,"errorMessage":"Could not find user @${targetUser}","messagePattern":"Could not find user @(.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/twitter/following.js","lineNumber":205,"sourceCode":"            'X-Twitter-Active-User': 'yes',\n        };\n\n        // Get userId from screen_name\n        const userLookup = unwrapBrowserResult(await page.evaluate(async (url, headers) => {\n            const resp = await fetch(url, { headers, credentials: 'include' });\n            if (!resp.ok) return { error: resp.status };\n            const d = await resp.json();\n            return { userId: d.data?.user?.result?.rest_id || null };\n        }, buildUserByScreenNameQueryUrl(userByScreenNameQueryId, targetUser), headers));\n        if (userLookup?.error === 401 || userLookup?.error === 403) {\n            throw new AuthRequiredError('x.com', `Twitter user lookup failed (HTTP ${userLookup.error})`);\n        }\n        if (userLookup?.error) {\n            throw new CommandExecutionError(`HTTP ${userLookup.error}: Failed to resolve Twitter user @${targetUser}`);\n        }\n        const userId = userLookup?.userId || null;\n        if (!userId)\n            throw new CommandExecutionError(`Could not find user @${targetUser}`);\n\n        const allUsers = [];\n        const seen = new Set();\n        let cursor = null;\n        let lastRawResponse = null;\n\n        // Runaway guard only; --limit and cursor exhaustion control normal pagination.\n        for (let i = 0; i < MAX_PAGINATION_PAGES && allUsers.length < limit; i++) {\n            const fetchCount = Math.min(50, limit - allUsers.length + 10);\n            const apiUrl = buildFollowingUrl(followingQueryId, userId, fetchCount, cursor);\n            const data = unwrapBrowserResult(await page.evaluate(async (url, headers) => {\n                const r = await fetch(url, { headers, credentials: 'include' });\n                return r.ok ? await r.json() : { error: r.status };\n            }, apiUrl, headers));\n            if (data?.error) {\n                if (data.error === 401 || data.error === 403)\n                    throw new AuthRequiredError('x.com', `Twitter following request failed (HTTP ${data.error})`);\n                throw new CommandExecutionError(describeTwitterApiError('Following', data.error));","sourceCodeStart":187,"sourceCodeEnd":223,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/twitter/following.js#L187-L223","documentation":"CommandExecutionError thrown when the UserByScreenName lookup succeeds (HTTP 200) but the response contains no user rest_id — d.data?.user?.result?.rest_id is null/undefined. This means Twitter did not return an account for the given screen name.","triggerScenarios":"After a non-error API response, userId is falsy: the screen name does not exist, was renamed, or the account is suspended/removed, so the nested rest_id path resolves to null.","commonSituations":"Typo in the handle; the account was deleted, renamed, or suspended; requesting a protected/withheld account from a region where it is unavailable; Twitter changing the UserByScreenName response shape after an API update so rest_id sits at a different path.","solutions":["Verify the handle exists by opening https://x.com/<name> in a browser","Check for typos or recent renames of the account","Retry after updating opencli if Twitter changed the response shape (rest_id path)","Use the numeric user ID directly if the CLI supports it, bypassing the screen-name lookup"],"exampleFix":"// before: nonexistent handle\n$ opencli twitter following @thisuserdoesnotexist12345\nError: Could not find user @thisuserdoesnotexist12345\n// after: use a real, existing handle\n$ opencli twitter following @elonmusk","handlingStrategy":"validation","validationCode":"// Pre-check that the handle exists before running the following command\nconst { execSync } = require('child_process');\nconst status = execSync(`curl -s -o /dev/null -w '%{http_code}' https://x.com/${handle.replace('@','')}`).trim();\nif (status !== '200') throw new Error(`@${handle.replace('@','')} does not exist or is unavailable`);","typeGuard":"function lookupSucceeded(d) {\n  return d && typeof d === 'object' && typeof d?.data?.user?.result?.rest_id === 'string' && d.data.user.result.rest_id.length > 0;\n}","tryCatchPattern":"try {\n  await cli.following(target);\n} catch (err) {\n  if (/Could not find user @/.test(err.message)) {\n    console.error('Check the handle at https://x.com/' + target.replace('@','') + ' — it may be renamed, deleted, or suspended.');\n  } else throw err;\n}","preventionTips":["Verify the handle exists on x.com before scripting against it","Watch for renamed/deleted/suspended accounts in tracked lists","Handle Twitter response-shape changes by keeping the CLI updated","Prefer numeric user IDs when available to avoid screen-name drift"],"tags":["twitter","user-lookup","not-found"],"backgroundTag":"resource-not-found","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}