{"record":{"id":"b90a19f08a11267b","repo":"jackwener/OpenCLI","slug":"failed-to-confirm-add-to-cart-success","errorCode":null,"errorMessage":"Failed to confirm add-to-cart success.","messagePattern":"Failed to confirm add-to-cart success\\.","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/coupang/add-to-cart.js","lineNumber":140,"sourceCode":"            throw new CommandExecutionError(`coupang add-to-cart evaluation failed: ${error?.message || error}`);\n        });\n        const loginHints = result?.loginHints ?? {};\n        if (loginHints.hasLoginLink && !loginHints.hasMyCoupang) {\n            throw new AuthRequiredError('coupang.com', 'Please log into Coupang in Chrome and retry.');\n        }\n        const actualProductId = normalizeProductId(result?.currentProductId || productId);\n        if (result?.reason === 'PRODUCT_MISMATCH') {\n            const observed = actualProductId ? `got ${actualProductId}` : 'no product id observed';\n            throw new CommandExecutionError(`Product mismatch: expected ${productId}, ${observed}`);\n        }\n        if (result?.reason === 'OPTION_REQUIRED') {\n            throw new CommandExecutionError('This product requires option selection and is not supported in v1.');\n        }\n        if (result?.reason === 'ADD_TO_CART_BUTTON_NOT_FOUND') {\n            throw new CommandExecutionError('Could not find an add-to-cart button on the product page.');\n        }\n        if (!result?.ok) {\n            throw new CommandExecutionError('Failed to confirm add-to-cart success.');\n        }\n        return [{\n                ok: true,\n                product_id: actualProductId || productId,\n                url: finalUrl,\n                message: 'Added to cart',\n            }];\n    },\n});\n","sourceCodeStart":122,"sourceCodeEnd":150,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/coupang/add-to-cart.js#L122-L150","documentation":"CommandExecutionError thrown when result.ok is falsy after all specific reason checks pass — i.e. the button was clicked but the script could not confirm success: neither a Korean 'added to cart' success message appeared nor did the cart count badge increase within the 2500ms wait window.","triggerScenarios":"Add-to-cart click succeeded but Coupang showed a confirmation in an unexpected format; confirmation took longer than 2500ms; a modal/interstitial appeared instead of the success message; cart-count selector ([class*=\"cart\"] .count, #headerCartCount, .cart-count) not present so increase couldn't be measured.","commonSituations":"Slow network making Coupang's confirmation toast late; logged-in state where Coupang opens an option/layer popup after clicking; cart-count element absent in current layout; intermittent anti-bot overlay swallowing the click.","solutions":["Retry the command — if the item actually got added, verify cart contents before re-adding to avoid duplicates","Increase the post-click wait time (setTimeout 2500ms) in buildAddToCartEvaluate if confirmations are slow","Check the page manually to see what appears after clicking add-to-cart and update the success-message regex /장바구니에 담|장바구니 담기 완료|added to cart/i","Verify the cart-count selector still exists in Coupang's current markup"],"exampleFix":"// before\n await new Promise((resolve) => setTimeout(resolve, 2500));\n// after\n await new Promise((resolve) => setTimeout(resolve, 5000));  // allow slow confirmations","handlingStrategy":"try-catch","validationCode":"// confirm success by reading the cart after the command\nconst cartCount = await page.evaluate(() => {\n  const n = document.querySelector('[class*=\"cart\"] .count, #headerCartCount, .cart-count');\n  return n ? Number(n.textContent.replace(/\\D/g, '')) : null;\n});","typeGuard":"function cartConfirmed(result) {\n  return result != null && result.ok === true && Array.isArray(result.items ?? result) === (result.ok === true);\n}\n// simpler: verify via returned ok flag\nfunction addToCartSucceeded(result) {\n  return Boolean(result && result.ok);\n}","tryCatchPattern":"try {\n  const result = await addToCart(page, productId);\n} catch (err) {\n  if (/Failed to confirm add-to-cart/.test(err.message)) {\n    // check the cart before re-adding to avoid duplicates\n    const inCart = await checkCartContains(page, productId);\n    if (!inCart) await addToCart(page, productId);\n    return;\n  }\n  throw err;\n}","preventionTips":["Verify cart contents before retrying to prevent duplicate additions","Allow extra time on slow networks for Coupang's confirmation toast","Keep success-message regex and cart-count selectors up to date with Coupang markup"],"tags":["coupang","ui-automation","verification-failed"],"backgroundTag":"cart-confirmation-timeout","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}