jackwener/OpenCLI · error · CommandExecutionError

Trip.com deals DOM extraction returned malformed rows

Error message

Trip.com deals DOM extraction returned malformed rows

What it means

CommandExecutionError thrown when the deals page's in-page extractor (buildDealsExtractJs) returns a value that is not an array — the extraction script itself failed or returned an unexpected shape rather than a list of tiles. This distinguishes a broken extractor/serialization from a page with zero deals.

Source

Thrown at clis/trip/deals.js:46

        'rank',
        'title', 'offer',
        'discount',
        'url',
    ],
    func: async (page, kwargs) => {
        const limit = parseListLimit(kwargs.limit);

        await page.goto(buildDealsUrl());
        const waitResult = await page.evaluate(WAIT_FOR_DEALS_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 !== 'content') {
            throw new CommandExecutionError(`Trip.com deals page did not render deal tiles (state=${String(waitResult)})`);
        }
        const raw = await page.evaluate(buildDealsExtractJs());
        if (!Array.isArray(raw)) {
            throw new CommandExecutionError('Trip.com deals DOM extraction returned malformed rows');
        }
        // The Top Deals hub is a permanent curated page, so once the wait confirms it
        // rendered, zero parsed tiles means the tile markup drifted, not an empty hub.
        if (raw.length === 0) {
            throw new CommandExecutionError('Trip.com deals hub rendered but no promotion tiles parsed (the tile markup may have changed)');
        }
        return raw.slice(0, limit).map((r, i) => ({
            rank: i + 1,
            title: r.title,
            offer: r.offer,
            discount: r.discount,
            url: r.url,
        }));
    },
});

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Rerun the command — a transient redirect/navigation often explains a one-off non-array result
  2. Confirm the browser session lands on the real Top Deals page (no redirect loop)
  3. Check that the extractor version matches the CLI version (reinstall/update the package)
  4. Debug buildDealsExtractJs to return a structured error object so the failure mode is diagnosable

Example fix

// before
const raw = await page.evaluate(buildDealsExtractJs());
if (!Array.isArray(raw)) {
    throw new CommandExecutionError('Trip.com deals DOM extraction returned malformed rows');
}
// after
const raw = await page.evaluate(buildDealsExtractJs());
if (!Array.isArray(raw)) {
    throw new CommandExecutionError(
        `Trip.com deals DOM extraction returned malformed rows (got ${typeof raw})`);
}
Defensive patterns

Strategy: type-guard

Validate before calling

// Verify the page context is stable before evaluating the extractor
const url = page.url();
if (!url.includes('deals')) console.warn('Page navigated away from deals hub; extraction may return non-array');

Type guard

function isArrayRows(v) {
    return Array.isArray(v);
}

Try / catch

try {
    const deals = await runTripDeals();
} catch (e) {
    if (e instanceof CommandExecutionError && /malformed rows/.test(e.message)) {
        // non-array extract: retry once; if persistent, log typeof result for diagnosis
    } else { throw e; }
}

Prevention

When it happens

Trigger: page.evaluate(buildDealsExtractJs()) resolves to null/undefined/an object instead of an array — e.g. the script threw internally and a wrapper returned an error object, or the page context was replaced by a navigation before evaluation finished.

Common situations: Page navigated mid-evaluation (redirect after goto); extractor script version mismatch with page globals; evaluate returning an error object from a caught in-page exception; Trip.com serving an SPA shell that aborts the script.

Understand the failure class

Related errors


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