{"record":{"id":"ea9586f665758944","repo":"jackwener/OpenCLI","slug":"instagram-post-share-failed","errorCode":null,"errorMessage":"Instagram post share failed","messagePattern":"Instagram post share failed","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/instagram/post.js","lineNumber":1247,"sourceCode":"async function ensureCaptionFilled(page, content) {\n    for (let attempt = 0; attempt < 6; attempt++) {\n        if (await captionMatches(page, content)) {\n            return;\n        }\n        if (attempt < 5) {\n            await page.wait({ time: 0.5 });\n        }\n    }\n    await page.screenshot({ path: '/tmp/instagram_post_caption_fill_debug.png' });\n    throw new CommandExecutionError('Instagram caption did not stick before sharing', 'Inspect /tmp/instagram_post_caption_fill_debug.png for the caption editor state');\n}\nasync function waitForPublishSuccess(page) {\n    let settledStreak = 0;\n    for (let attempt = 0; attempt < 90; attempt++) {\n        const result = await page.evaluate(buildPublishStatusProbeJs());\n        if (result?.failed) {\n            await page.screenshot({ path: '/tmp/instagram_post_share_debug.png' });\n            throw new CommandExecutionError('Instagram post share failed', 'Inspect /tmp/instagram_post_share_debug.png for the share failure state');\n        }\n        if (result?.ok) {\n            return result.url || '';\n        }\n        if (result?.settled) {\n            settledStreak += 1;\n            if (settledStreak >= 3)\n                return '';\n        }\n        else {\n            settledStreak = 0;\n        }\n        if (attempt < 89) {\n            await page.wait({ time: 1 });\n        }\n    }\n    await page.screenshot({ path: '/tmp/instagram_post_share_debug.png' });\n    throw new CommandExecutionError('Instagram post share confirmation did not appear', 'Inspect /tmp/instagram_post_share_debug.png for the final publish state');","sourceCodeStart":1229,"sourceCodeEnd":1265,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/instagram/post.js#L1229-L1265","documentation":"waitForPublishSuccess polls the Instagram composer page up to 90 times with a DOM probe (buildPublishStatusProbeJs). When the probe detects an explicit failure state in the publish dialog, it throws this CommandExecutionError after saving a debug screenshot. It means Instagram itself reported the share as failed (e.g. an in-dialog 'Couldn't post' message), not that the CLI timed out.","triggerScenarios":"During clis/instagram/post.js share flow: the in-page probe returns result.failed because the publish dialog shows a failure notice after clicking Share — e.g. media upload rejected, rate limit, or Instagram-side post creation error.","commonSituations":"Instagram rate-limiting or action-block on the account; unsupported media (size/format) rejected server-side; network drop mid-upload; transient Instagram UI/API changes so the probe misreads the dialog; account flagged for suspicious automation.","solutions":["Open /tmp/instagram_post_share_debug.png to see the exact failure state Instagram showed in the dialog","Wait and retry later if the dialog shows a rate-limit / 'try again later' message (action block)","Re-encode/rescale the media (valid JPG/PNG/MP4 within Instagram limits) and retry","Verify the logged-in session is valid and not restricted (log in manually in the browser session)","Re-run with OPENCLI_INSTAGRAM_CAPTURE=1 to inspect captured protocol responses for the failing request"],"exampleFix":"// before: immediate throw on first failed probe\nif (result?.failed) {\n  await page.screenshot({ path: '/tmp/instagram_post_share_debug.png' });\n  throw new CommandExecutionError('Instagram post share failed', hint);\n}\n// after: allow a short retry streak before giving up\nif (result?.failed) {\n  failedStreak += 1;\n  if (failedStreak >= 3) {\n    await page.screenshot({ path: '/tmp/instagram_post_share_debug.png' });\n    throw new CommandExecutionError('Instagram post share failed', hint);\n  }\n}","handlingStrategy":"try-catch","validationCode":"// Before posting, confirm the session can reach Instagram's composer without dialogs\nconst hasDialog = await page.evaluate(`!!document.querySelector('div[role=\"dialog\"]')`);\nif (hasDialog) throw new Error('Dismiss open dialogs before posting');","typeGuard":"function isPublishProbeResult(r) {\n  return r !== null && typeof r === 'object' && ('ok' in r || 'failed' in r || 'settled' in r);\n}","tryCatchPattern":"try {\n  await postToInstagram(media, caption);\n} catch (e) {\n  if (e instanceof CommandExecutionError && e.message === 'Instagram post share failed') {\n    // inspect /tmp/instagram_post_share_debug.png, back off, and retry later\n    await sleep(rateLimitBackoff);\n    return retryPost(media, caption);\n  }\n  throw e;\n}","preventionTips":["Keep posting volume under Instagram rate limits (space posts minutes apart)","Pre-validate media size/format/resolution against Instagram limits before sharing","Use a warmed, regularly-used session rather than a fresh login","Archive /tmp/instagram_post_share_debug.png from each failure to spot recurring dialog states"],"tags":["instagram","automation","publish-failed","screenshot-debug"],"backgroundTag":"instagram-publish-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}