jackwener/OpenCLI · error · CommandExecutionError
Could not resolve @${username}
Error message
Could not resolve @${username} What it means
After building UserByScreenName GraphQL headers, resolveUserTimelineContext evaluates a fetch in the page to map a @handle to its numeric rest_id. If the response is not ok or the JSON lacks data.user.result.rest_id, it throws CommandExecutionError `Could not resolve @<username>`. This means Twitter did not return a user for that screen name under the current session.
Source
Thrown at clis/twitter/user-timeline.js:207
const ct0 = cookies.find((cookie) => cookie.name === 'ct0')?.value || null;
if (!ct0) throw new AuthRequiredError('x.com', 'Not logged into x.com (no ct0 cookie)');
const userTweetsOperation = await resolveTwitterOperationMetadata(page, 'UserTweets', USER_TWEETS_OPERATION);
const userByScreenNameOperation = await resolveTwitterOperationMetadata(page, 'UserByScreenName', USER_BY_SCREEN_NAME_OPERATION);
const headers = JSON.stringify({
Authorization: `Bearer ${decodeURIComponent(TWITTER_BEARER_TOKEN)}`,
'X-Csrf-Token': ct0,
'X-Twitter-Auth-Type': 'OAuth2Session',
'X-Twitter-Active-User': 'yes',
});
const userByScreenNameUrl = buildUserByScreenNameUrl(userByScreenNameOperation, username);
const userId = unwrapBrowserResult(await page.evaluate(`async () => {
const resp = await fetch(${JSON.stringify(userByScreenNameUrl)}, { headers: ${headers}, credentials: 'include' });
if (!resp.ok) return null;
const data = await resp.json();
return data?.data?.user?.result?.rest_id || null;
}`));
if (!userId) throw new CommandExecutionError(`Could not resolve @${username}`);
return { username, userId, headers, userTweetsOperation };
}
export async function fetchUserTimelinePage(page, context, cursor, count) {
const url = buildUserTweetsUrl(context.userTweetsOperation, context.userId, count, cursor);
return normalizeTwitterGraphqlPayload(await page.evaluate(`async () => {
const response = await fetch(${JSON.stringify(url)}, { headers: ${context.headers}, credentials: 'include' });
return response.ok ? await response.json() : { error: response.status };
}`));
}
View on GitHub (pinned to 49907e53dc)
Solutions
- Double-check the handle: confirm the account exists by visiting https://x.com/<username> in the same logged-in browser.
- Retry later if X is rate-limiting or having an incident; verify with a browser request that UserByScreenName returns 200.
- Strip any leading '@' or trailing whitespace from the username before calling.
- Refresh the UserByScreenName operation metadata (queryId) if X rotated it, and re-login if the session degraded.
Example fix
// before await fetchUserTimeline(page, 'elonmusk '); // trailing space // after const username = raw.trim().replace(/^@/, ''); await fetchUserTimeline(page, username);
Defensive patterns
Strategy: validation
Validate before calling
const handle = raw.trim().replace(/^@/, '');
if (!/^[A-Za-z0-9_]{1,15}$/.test(handle)) {
throw new Error(`Not a valid X handle: ${raw}`);
} Try / catch
try {
await fetchUserTimeline(page, handle);
} catch (err) {
if (/Could not resolve @/.test(err.message)) {
console.error(`Account @${handle} not found, renamed, or suspended; verify at https://x.com/${handle}`);
return null;
}
throw err;
} Prevention
- Normalize handles: trim, strip leading '@', validate against /^[A-Za-z0-9_]{1,15}$/.
- Confirm the account exists before batch runs (visit x.com/<handle> or one lookup).
- Back off and retry on rate-limit-like failures; refresh operation queryIds when X rotates them.
When it happens
Trigger: Passing a username that does not exist, was renamed/deactivated/suspended, is misspelled (including a leading '@' if the URL builder doesn't strip it), or calling while the GraphQL request is rejected (rate limited, auth issues) so resp.ok is false and userId is null.
Common situations: Typo in the handle; account deleted or renamed since it was saved; querying a protected account while not following it; X rate-limiting the UserByScreenName endpoint; stale operation metadata (queryId rotation) causing non-ok responses.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- device_follow
- ${probe.detail}
- message (describeTwitterApiError('TweetResultByRestId', rawR
- Bookmarks
- twitter_bookmarks_protocol_error
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/16f5d7f9292aa65c.
Report an issue: GitHub.