jackwener/OpenCLI · error · CommandExecutionError

Trip.com car DOM extraction returned malformed rows

Error message

Trip.com car DOM extraction returned malformed rows

What it means

This CommandExecutionError is thrown when page.evaluate(buildCarExtractJs()) returns a non-array — the car-listing page rendered, but the DOM extraction script produced malformed output instead of a list of car rows. It indicates the extraction script no longer matches the live page structure; empty car lists are reported by error 3907 instead.

Source

Thrown at clis/trip/car.js:59

    func: async (page, kwargs) => {
        const cityId = parseCityId('city', kwargs.city);
        const limit = parseListLimit(kwargs.limit);

        const listUrl = buildCarListUrl(cityId);
        await page.goto(listUrl);
        const waitResult = await page.evaluate(WAIT_FOR_CARS_JS);
        if (waitResult === 'captcha') {
            throw new AuthRequiredError('trip.com', 'Trip.com is asking for a verification; complete it in your browser session and retry');
        }
        if (waitResult === 'empty') {
            throw new EmptyResultError('trip car', `No car rentals for city id ${cityId}`);
        }
        if (waitResult !== 'content') {
            throw new CommandExecutionError(`Trip.com car listing did not render (state=${String(waitResult)}); check the carhire city id`);
        }
        const raw = await page.evaluate(buildCarExtractJs());
        if (!Array.isArray(raw)) {
            throw new CommandExecutionError('Trip.com car DOM extraction returned malformed rows');
        }
        if (raw.length === 0) {
            throw new CommandExecutionError('Trip.com car cards rendered but parser did not find required price anchors');
        }
        return raw.slice(0, limit).map((r, i) => ({
            rank: i + 1,
            category: r.category,
            vehicle: r.vehicle,
            seats: r.seats,
            price: r.price,
            currency: r.currency,
            url: listUrl,
        }));
    },
});

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Retry once — transient render races can yield malformed extraction; persistent failure indicates a DOM change.
  2. Open the carhire URL in a normal browser and compare card markup against buildCarExtractJs selectors in clis/trip/utils.js.
  3. Update the extraction script's price-anchor selectors to the new Trip.com carhire card structure.
  4. Check for a library update or patch addressing the Trip.com front-end change.

Example fix

// before: assuming array always returned
const raw = await page.evaluate(buildCarExtractJs());
const rows = raw.slice(0, limit);
// after: caller-side guard
const raw = await page.evaluate(buildCarExtractJs());
if (!Array.isArray(raw)) throw new Error('Trip.com car extraction non-array; selectors likely stale');
const rows = raw.slice(0, limit);
Defensive patterns

Strategy: type-guard

Validate before calling

null

Type guard

function isCarRows(value) {
  return Array.isArray(value) && value.every(
    (r) => r && typeof r === 'object' && typeof r.name === 'string'
  );
}

Try / catch

try {
  return await runCli(['trip', 'car', '--city-id', cityId]);
} catch (e) {
  if (/car DOM extraction returned malformed rows/.test(e.message)) {
    // extraction script out of sync with live carhire DOM
    throw new Error('Trip.com car extraction stale; update buildCarExtractJs selectors');
  }
  throw e;
}

Prevention

When it happens

Trigger: Running `trip car` when buildCarExtractJs' in-page script returns null/undefined/an object rather than an array — typically because the carhire card markup changed so the script's row collection fails, or a partially rendered page lacks the expected containers.

Common situations: Trip.com redesign of carhire result cards breaking the extract script's selectors; a localized or A/B page variant with different markup; an interstitial or error page that passes the wait check but has no standard car card DOM.

Understand the failure class

Related errors


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