{"record":{"id":"682a7bf26d355b51","repo":"jackwener/OpenCLI","slug":"instagram-image-upload-failed","errorCode":null,"errorMessage":"Instagram image upload failed","messagePattern":"Instagram image upload failed","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/instagram/post.js","lineNumber":776,"sourceCode":"        if (retry instanceof HTMLElement) {\n          retry.click();\n          return { ok: true };\n        }\n      }\n      return { ok: false };\n    })()\n  `);\n    return !!result?.ok;\n}\nasync function waitForPreview(page, maxWaitSeconds = 12) {\n    const attempts = Math.max(1, Math.ceil(maxWaitSeconds));\n    for (let attempt = 0; attempt < attempts; attempt++) {\n        const state = await inspectUploadStage(page);\n        if (state.state === 'preview')\n            return;\n        if (state.state === 'failed') {\n            await page.screenshot({ path: '/tmp/instagram_post_preview_debug.png' });\n            throw makeUploadFailure('Inspect /tmp/instagram_post_preview_debug.png. ' + (state.detail || ''));\n        }\n        if (attempt < attempts - 1)\n            await page.wait({ time: 1 });\n    }\n    await page.screenshot({ path: '/tmp/instagram_post_preview_debug.png' });\n    throw new CommandExecutionError('Instagram image preview did not appear after upload', 'The selected file input may not match the active composer; inspect /tmp/instagram_post_preview_debug.png');\n}\nasync function waitForPreviewMaybe(page, maxWaitSeconds = 4) {\n    const attempts = Math.max(1, Math.ceil(maxWaitSeconds * 2));\n    for (let attempt = 0; attempt < attempts; attempt++) {\n        const state = await inspectUploadStage(page);\n        if (state.state !== 'pending')\n            return state;\n        if (attempt < attempts - 1)\n            await page.wait({ time: 0.5 });\n    }\n    return { state: 'pending' };\n}","sourceCodeStart":758,"sourceCodeEnd":794,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/instagram/post.js#L758-L794","documentation":"waitForPreview polls inspectUploadStage after the image file input is set, waiting for Instagram to render an upload preview. If Instagram reports a failed upload state, a debug screenshot is saved to /tmp/instagram_post_preview_debug.png and a CommandExecutionError (wrapped by makeUploadFailure as 'Instagram image upload failed') is thrown. It also throws if no preview appears after all polling attempts.","triggerScenarios":"Calling the instagram post/upload flow when the uploaded file is rejected by Instagram (unsupported format/size) or the composer never renders a preview element within the polling window.","commonSituations":"Uploading an unsupported image (wrong mime, corrupt file, oversized), selecting a file input that does not match the active composer (wrong modal/tab), Instagram DOM changes that break stage detection, slow network making the preview exceed the timeout.","solutions":["Inspect /tmp/instagram_post_preview_debug.png to see what the page actually shows","Convert the image to a supported format (JPG/PNG) and reasonable size, then retry","Retry the upload; transient network slowness often exceeds the poll window","Update the CLI if Instagram changed its composer DOM so inspectUploadStage detects the preview again"],"exampleFix":"// before\nconst buf = fs.readFileSync('photo.heic');\nawait postImage(page, buf);\n// after\nconst jpg = await sharp('photo.heic').jpeg({ quality: 90 }).toBuffer();\nawait postImage(page, jpg);","handlingStrategy":"validation","validationCode":"const stat = fs.statSync(file);\nconst okType = /\\.(jpe?g|png|webp)$/i.test(file);\nconst okSize = stat.size > 0 && stat.size < 8 * 1024 * 1024;\nif (!okType || !okSize) throw new Error('image must be jpg/png/webp under 8MB: ' + file);","typeGuard":"function isUploadableImage(file) {\n  return /^image\\/(jpe?g|png|webp)$/.test(mimeLookup(file));\n}","tryCatchPattern":"try {\n  await instagramPost(page, file);\n} catch (e) {\n  if (/Instagram image upload failed/.test(e.message)) {\n    console.error('see /tmp/instagram_post_preview_debug.png', e.message);\n  }\n  throw e;\n}","preventionTips":["Pre-validate image format and size before upload","Keep the poll timeout generous for slow networks","Check /tmp/instagram_post_preview_debug.png after every failure","Keep the CLI updated against Instagram DOM changes"],"tags":["upload","instagram","browser-automation"],"backgroundTag":"upload-preview-timeout","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}