{"record":{"id":"8caf71f8e71d1350","repo":"jackwener/OpenCLI","slug":"could-not-resolve-article-tweetid-to-a-tweet-id","errorCode":null,"errorMessage":"Could not resolve article ${tweetId} to a tweet ID. The article page may not contain a linked tweet.","messagePattern":"Could not resolve article (.+?) to a tweet ID\\. The article page may not contain a linked tweet\\.","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/twitter/article.js","lineNumber":53,"sourceCode":"            await page.wait(3);\n            const resolvedId = await page.evaluate(`\n        (function() {\n          var links = document.querySelectorAll('a[href*=\"/status/\"]');\n          for (var i = 0; i < links.length; i++) {\n            var m = links[i].href.match(/\\\\/status\\\\/(\\\\d+)/);\n            if (m) return m[1];\n          }\n          var og = document.querySelector('meta[property=\"og:url\"]');\n          if (og && og.content) {\n            var m2 = og.content.match(/\\\\/status\\\\/(\\\\d+)/);\n            if (m2) return m2[1];\n          }\n          return null;\n        })()\n      `);\n            const resolvedTweetId = unwrapBrowserResult(resolvedId);\n            if (!resolvedTweetId || typeof resolvedTweetId !== 'string') {\n                throw new CommandExecutionError(`Could not resolve article ${tweetId} to a tweet ID. The article page may not contain a linked tweet.`);\n            }\n            tweetId = resolvedTweetId;\n        }\n        // Navigate to the tweet page for cookie context\n        await page.goto(`https://x.com/i/status/${tweetId}`);\n        await page.wait(3);\n        // Read CSRF token directly from the cookie store via CDP — zero page.evaluate round-trip\n        const cookies = await page.getCookies({ url: 'https://x.com' });\n        const ct0 = cookies.find((c) => c.name === 'ct0')?.value || null;\n        if (!ct0)\n            throw new AuthRequiredError('x.com', 'Not logged into x.com (no ct0 cookie)');\n        const queryId = await resolveTwitterQueryId(page, 'TweetResultByRestId', TWEET_RESULT_BY_REST_ID_QUERY_ID);\n        const rawResult = unwrapBrowserResult(await page.evaluate(`\n      async () => {\n        const tweetId = ${JSON.stringify(tweetId)};\n        const ct0 = ${JSON.stringify(ct0)};\n\n        const bearer = ${JSON.stringify(TWITTER_BEARER_TOKEN)};","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/twitter/article.js#L35-L71","documentation":"The twitter article command resolves an X article (long-form post) to its linked tweet before fetching it. An in-page script attempts to extract the tweet id from the article page; if the resolved id is missing or not a string, a CommandExecutionError is thrown because X articles do not always embed a tweet link. The command can only proceed when a concrete tweet id exists.","triggerScenarios":"Passing an article id whose page's DOM/state does not contain a linked tweet — the browser evaluate returns null or a non-string and the guard rejects it.","commonSituations":"Articles that are pure long-form posts with no embedded tweet, X rendering changes that move/remove the tweet link, deleting the associated tweet after the article was published, or passing a truncated/incorrect article id.","solutions":["Verify the article actually contains a linked tweet (open it on x.com and check)","Re-check the article id/tweetId argument for typos or truncation","Retry later if X's page markup changed — adapter query scripts may need updating upstream","If a tweet link exists but isn't found, report/update resolveTwitterQueryId scripts or extract the id manually and use the tweet command"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"function resolvedTweetIdIsUsable(v) { return typeof v === 'string' && v.length > 0 && /^\\d+$/.test(v); }","tryCatchPattern":"try {\n  await articleCmd({ tweetId });\n} catch (err) {\n  if (err.message.includes('Could not resolve article')) {\n    console.error('Article has no linked tweet — open it on x.com to verify, or pass the tweet id directly');\n  } else throw err;\n}","preventionTips":["Verify the article page actually links to a tweet before automating","Double-check article ids for typos/truncation","Keep the adapter's page scripts updated after X markup changes","Fall back to the plain tweet command when the tweet id is known"],"tags":["browser","scraping","twitter"],"backgroundTag":"element-not-found","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}