{"record":{"id":"4df21cd49522b071","repo":"moeru-ai/airi","slug":"failed-to-like-tweet-errortomessage-error","errorCode":null,"errorMessage":"Failed to like tweet: ${errorToMessage(error)}","messagePattern":"Failed to like tweet: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"integrations/twitter-services/src/core/services/tweet.ts","lineNumber":139,"sourceCode":"      const isAlreadyLiked = await page.$eval(\n        SELECTORS.TIMELINE.LIKE_BUTTON,\n        el => el.getAttribute('aria-pressed') === 'true',\n      )\n\n      if (!isAlreadyLiked) {\n        await likeButton.click()\n        // Wait for the like to register\n        await page.waitForFunction(\n          `document.querySelector('${SELECTORS.TIMELINE.LIKE_BUTTON}')?.getAttribute('aria-pressed') === 'true'`,\n          { timeout: 5000 },\n        )\n      }\n\n      return true\n    }\n    catch (error: unknown) {\n      console.error('Error liking tweet:', error)\n      throw new Error(`Failed to like tweet: ${errorToMessage(error)}`)\n    }\n  }\n\n  /**\n   * Retweets a tweet with the given ID\n   */\n  async function retweet(tweetId: string): Promise<boolean> {\n    try {\n      const page = ctx.page\n      await page.goto(`${TWITTER_BASE_URL}/i/status/${tweetId}`)\n      await page.waitForSelector(SELECTORS.TIMELINE.TWEET)\n\n      // Click retweet button to open modal\n      const retweetButton = await page.$(SELECTORS.TIMELINE.RETWEET_BUTTON)\n      if (!retweetButton) {\n        throw new Error('Retweet button not found')\n      }\n","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/moeru-ai/airi/blob/27111382b4a79a7e983289d6e983a06af185ed0f/integrations/twitter-services/src/core/services/tweet.ts#L121-L157","documentation":"Thrown by likeTweet as the outer catch-all: any error inside the function — 'Like button not found', a click failure, or a waitForFunction timeout (the aria-pressed 'true' assertion did not hold within 5000 ms) — is caught, logged to console.error, and re-thrown as a new Error prefixed 'Failed to like tweet:' with the original message stringified via errorToMessage. The original cause is not attached via .cause.","triggerScenarios":"The like button was clicked but the aria-pressed state did not flip to 'true' within 5s (waitForFunction timeout); 'Like button not found' propagated from the inner check; the click threw because the element detached; the page navigated away during the wait.","commonSituations":"X rate-limits or throttles the like action so the state never updates; network lag exceeds the 5s window; the tweet is already liked but aria-pressed read falsely as 'false' (stale read); selector drift on aria-pressed; the session is read-only (view-only/locked account).","solutions":["Read the wrapped message — 'Like button not found' → fix selectors (see error 177); a waitForFunction timeout → like did not register, retry or increase the timeout.","Increase the waitForFunction timeout (currently 5000 ms) for slow connections.","Retry the like after a short delay for transient throttling.","Confirm the account has write permission (not view-only/limited)."],"exampleFix":"// before\ncatch (error) {\n  console.error('Error liking tweet:', error)\n  throw new Error(`Failed to like tweet: ${errorToMessage(error)}`)\n}\n\n// after — preserve cause, retry once on registration timeout\ncatch (error) {\n  if (/waitForFunction/i.test(errorToMessage(error))) {\n    await sleep(1500)\n    // one retry of the click+wait\n  }\n  throw new Error(`Failed to like tweet: ${errorToMessage(error)}`, { cause: error })\n}","handlingStrategy":"retry","validationCode":null,"typeGuard":"function isLikeTweetError(e: unknown): boolean {\n  return e instanceof Error && /Failed to like tweet:/.test(e.message)\n}","tryCatchPattern":"try {\n  await tweetServices.tweet.likeTweet(tweetId)\n} catch (e) {\n  if (e instanceof Error && /Failed to like tweet:/.test(e.message)) {\n    await sleep(2000)\n    return await tweetServices.tweet.likeTweet(tweetId) // one retry for transient throttling\n  }\n  throw e\n}","preventionTips":["Increase the 5000 ms waitForFunction window on slow connections.","Retry once after a short delay to absorb X throttling.","Confirm the account has write permission (not view-only/limited).","Preserve the original cause via the Error options bag for diagnosis."],"tags":["twitter","puppeteer","like","browser","timeout","catch-all"],"backgroundTag":null,"analyzedSha":"27111382b4a79a7e983289d6e983a06af185ed0f","analyzedAt":"2026-08-12T18:33:34.132Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}