{"record":{"id":"ebd8965181dd1cd2","repo":"jackwener/OpenCLI","slug":"coupang-com","errorCode":null,"errorMessage":"coupang.com","messagePattern":"coupang\\.com","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/coupang/add-to-cart.js","lineNumber":126,"sourceCode":"    func: async (page, kwargs) => {\n        const rawProductId = kwargs['product-id'];\n        if (!rawProductId && !kwargs.url) {\n            throw new ArgumentError('Either --product-id or --url is required');\n        }\n        const productId = rawProductId\n            ? requireProductIdArg(rawProductId, 'product-id')\n            : requireProductIdArg(kwargs.url, '--url');\n        const targetUrl = canonicalizeProductUrl(kwargs.url, productId);\n        const finalUrl = targetUrl || canonicalizeProductUrl('', productId);\n        await page.goto(finalUrl).catch((error) => {\n            throw new CommandExecutionError(`coupang add-to-cart navigation failed: ${error?.message || error}`);\n        });\n        const result = await page.evaluate(buildAddToCartEvaluate(productId)).catch((error) => {\n            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,","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/coupang/add-to-cart.js#L108-L144","documentation":"This AuthRequiredError('coupang.com') is thrown when the in-page add-to-cart evaluation reports a logged-out state: the page still shows a login link ('a[href*=\"login\"]' or Korean 로그인 link) and does NOT contain the 마이쿠팡 (My Coupang) text. The library refuses to proceed with add-to-cart because cart operations require an authenticated Coupang session in the attached Chrome profile.","triggerScenarios":"Running the coupang add-to-cart command while the controlled Chrome page has no logged-in Coupang session; page.evaluate's loginHints check (hasLoginLink && !hasMyCoupang) fires after evaluation completes. Also fires if Coupang redirected the product page to an anonymous layout.","commonSituations":"Fresh Chrome profile never logged into Coupang; Coupang session expired (cookies aged out); user logged out manually; testing from an IP/region where Coupang forces anonymous layout.","solutions":["Open Coupang in the controlled Chrome profile and log in at https://login.coupang.com/login/login.pang, then retry","Verify the correct Chrome profile/user-data-dir is attached (one that has an existing Coupang session)","Confirm session cookies AID/MEMBER_ID/LMSESSIONID exist for https://www.coupang.com","Check you are not being served an anonymous/regional variant of Coupang (e.g. non-KR IP redirect)"],"exampleFix":"// before\n coupang add-to-cart --product-id 12345  # AuthRequiredError: coupang.com\n// after\n coupang auth login coupang   # complete login in Chrome first\n coupang add-to-cart --product-id 12345","handlingStrategy":"try-catch","validationCode":"const cookies = await page.getCookies({ url: 'https://www.coupang.com' });\nconst loggedIn = cookies.some(c => /^(AID|MEMBER_ID|LMSESSIONID)$/.test(c.name) && c.value);\nif (!loggedIn) throw new Error('Log into Coupang before running add-to-cart');","typeGuard":"function isLoggedIn(loginHints) {\n  return typeof loginHints === 'object' && loginHints !== null &&\n    loginHints.hasLoginLink === true && loginHints.hasMyCoupang === false;\n}","tryCatchPattern":"try {\n  await addToCart(page, productId);\n} catch (err) {\n  if (err instanceof AuthRequiredError && err.site === 'coupang.com') {\n    console.error('Open Chrome, log into Coupang, then retry.');\n    return;\n  }\n  throw err;\n}","preventionTips":["Log into Coupang in the controlled Chrome profile before automation runs","Verify session cookies (AID/MEMBER_ID/LMSESSIONID) exist before invoking cart commands","Run coupang auth verify coupang as a preflight in your script"],"tags":["authentication","coupang","login-required"],"backgroundTag":"site-auth-required","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}