jackwener/OpenCLI · error · CommandExecutionError

Unexpected Xiaohongshu search filter result shape.

Error message

Unexpected Xiaohongshu search filter result shape.

What it means

requireFilterApplication validates the result of the in-browser script that applies search filter chips. The payload must unwrap to a non-array object with a string status field; otherwise this CommandExecutionError is thrown. It means the filter-application script did not return the expected {status, detail} contract at all.

Source

Thrown at clis/xiaohongshu/search.js:500

          }
          if (stableSamples < 3) {
            return { status: 'timeout', detail: request.group + '/' + request.option };
          }
          const finalPanels = panels();
          const finalFound = finalPanels.length === 1 ? findOption(finalPanels[0], request) : null;
          if (!finalFound || finalFound.status !== 'ok' || !isActive(finalFound.option)) {
            return { status: 'inactive', detail: request.group + '/' + request.option };
          }
        }
        return { status: 'ok' };
      })()
    `;
}

function requireFilterApplication(payload) {
    const result = unwrapEvaluateResult(payload);
    if (!result || typeof result !== 'object' || Array.isArray(result) || typeof result.status !== 'string') {
        throw new CommandExecutionError('Unexpected Xiaohongshu search filter result shape.');
    }
    if (result.status === 'ok') {
        return;
    }
    const detail = typeof result.detail === 'string' ? result.detail : 'unknown';
    if (result.status === 'auth') {
        throw new AuthRequiredError('www.xiaohongshu.com', 'Xiaohongshu search filters require a logged-in browser session');
    }
    if (result.status === 'timeout') {
        throw new TimeoutError(`xiaohongshu search filter ${detail}`, FILTER_SETTLE_SECONDS);
    }
    if (result.status === 'location') {
        throw new CommandExecutionError(`Xiaohongshu location filter was not applied (${detail}); enable browser geolocation permission.`);
    }
    if (result.status === 'capability') {
        throw new CommandExecutionError(`Xiaohongshu account-scoped filter was unavailable (${detail}); verify login and account access.`);
    }
    if (result.status === 'inactive') {

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Log the raw evaluate payload before validation to see what actually came back
  2. Ensure the search results page is loaded and stable (no redirect/login wall) before applying filters
  3. Update the injected filter script to catch its own errors and return {status:'error', detail} instead of throwing
  4. Verify unwrapEvaluateResult handles your specific browser driver's result wrapping

Example fix

// before
const result = unwrapEvaluateResult(payload);
if (!result || typeof result !== 'object' || Array.isArray(result) || typeof result.status !== 'string') {
  throw new CommandExecutionError('Unexpected Xiaohongshu search filter result shape.');
}
// after
const result = unwrapEvaluateResult(payload);
if (!result || typeof result !== 'object' || Array.isArray(result) || typeof result.status !== 'string') {
  console.error('filter payload:', JSON.stringify(payload));
  throw new CommandExecutionError('Unexpected Xiaohongshu search filter result shape; check for login walls or DOM changes.');
}
Defensive patterns

Strategy: type-guard

Validate before calling

function looksLikeFilterResult(p) {
  const r = p?.value ?? p;
  return !!r && typeof r === 'object' && !Array.isArray(r) && typeof r.status === 'string';
}
if (!looksLikeFilterResult(rawFilterPayload)) throw new Error('filter script returned unexpected shape');

Type guard

const isFilterResult = (r) =>
  r !== null && typeof r === 'object' && !Array.isArray(r) && typeof r.status === 'string';

Try / catch

try {
  requireFilterApplication(raw);
} catch (e) {
  if (e.message.includes('filter result shape')) {
    console.error('raw filter payload:', JSON.stringify(raw));
    // page likely navigated or the injected script crashed; reload and retry once
  } else throw e;
}

Prevention

When it happens

Trigger: page.evaluate for filter application returns undefined/null (script crashed, page navigated mid-run), returns an array, or the browser driver wraps the result in an unexpected structure that unwrapEvaluateResult cannot normalize.

Common situations: Xiaohongshu redirected the page (login wall, anti-bot) while the filter script ran; a DOM change threw inside the injected script so it never returned a status; driver/CDP serialization quirks dropping the return value.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


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