jackwener/OpenCLI · error · CommandExecutionError

Failed to confirm add-to-cart success.

Error message

Failed to confirm add-to-cart success.

What it means

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.

Source

Thrown at clis/coupang/add-to-cart.js:140

            throw new CommandExecutionError(`coupang add-to-cart evaluation failed: ${error?.message || error}`);
        });
        const loginHints = result?.loginHints ?? {};
        if (loginHints.hasLoginLink && !loginHints.hasMyCoupang) {
            throw new AuthRequiredError('coupang.com', 'Please log into Coupang in Chrome and retry.');
        }
        const actualProductId = normalizeProductId(result?.currentProductId || productId);
        if (result?.reason === 'PRODUCT_MISMATCH') {
            const observed = actualProductId ? `got ${actualProductId}` : 'no product id observed';
            throw new CommandExecutionError(`Product mismatch: expected ${productId}, ${observed}`);
        }
        if (result?.reason === 'OPTION_REQUIRED') {
            throw new CommandExecutionError('This product requires option selection and is not supported in v1.');
        }
        if (result?.reason === 'ADD_TO_CART_BUTTON_NOT_FOUND') {
            throw new CommandExecutionError('Could not find an add-to-cart button on the product page.');
        }
        if (!result?.ok) {
            throw new CommandExecutionError('Failed to confirm add-to-cart success.');
        }
        return [{
                ok: true,
                product_id: actualProductId || productId,
                url: finalUrl,
                message: 'Added to cart',
            }];
    },
});

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Retry the command — if the item actually got added, verify cart contents before re-adding to avoid duplicates
  2. Increase the post-click wait time (setTimeout 2500ms) in buildAddToCartEvaluate if confirmations are slow
  3. Check the page manually to see what appears after clicking add-to-cart and update the success-message regex /장바구니에 담|장바구니 담기 완료|added to cart/i
  4. Verify the cart-count selector still exists in Coupang's current markup

Example fix

// before
 await new Promise((resolve) => setTimeout(resolve, 2500));
// after
 await new Promise((resolve) => setTimeout(resolve, 5000));  // allow slow confirmations
Defensive patterns

Strategy: try-catch

Validate before calling

// confirm success by reading the cart after the command
const cartCount = await page.evaluate(() => {
  const n = document.querySelector('[class*="cart"] .count, #headerCartCount, .cart-count');
  return n ? Number(n.textContent.replace(/\D/g, '')) : null;
});

Type guard

function cartConfirmed(result) {
  return result != null && result.ok === true && Array.isArray(result.items ?? result) === (result.ok === true);
}
// simpler: verify via returned ok flag
function addToCartSucceeded(result) {
  return Boolean(result && result.ok);
}

Try / catch

try {
  const result = await addToCart(page, productId);
} catch (err) {
  if (/Failed to confirm add-to-cart/.test(err.message)) {
    // check the cart before re-adding to avoid duplicates
    const inCart = await checkCartContains(page, productId);
    if (!inCart) await addToCart(page, productId);
    return;
  }
  throw err;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/b90a19f08a11267b. Report an issue: GitHub.