jackwener/OpenCLI · error · CommandExecutionError

${label} did not include a stable text value.

Error message

${label} did not include a stable text value.

What it means

requireText() throws CommandExecutionError when the cleaned value for `label` is empty (null/undefined/whitespace). It guards that a required text field extracted from a page actually contains content.

Source

Thrown at clis/autohome/utils.js:114

export function requireLimit(value, def, max) {
    const raw = value == null || value === '' ? def : value;
    const n = typeof raw === 'number' ? raw : Number(String(raw).trim());
    if (!Number.isInteger(n) || n < 1 || n > max) {
        throw new ArgumentError(`limit must be an integer between 1 and ${max}`);
    }
    return n;
}

export function requireStableId(value, label) {
    const id = String(value ?? '').trim();
    if (!/^\d+$/.test(id)) throw new CommandExecutionError(`${label} did not include a stable numeric id.`);
    return id;
}

export function requireText(value, label) {
    const text = clean(value);
    if (!text) throw new CommandExecutionError(`${label} did not include a stable text value.`);
    return text;
}

export function assertPlainObject(value, label) {
    if (!value || typeof value !== 'object' || Array.isArray(value)) {
        throw new CommandExecutionError(`${label} returned an unexpected payload shape; expected an object.`);
    }
    return value;
}

/** Fetch an Autohome page as text. The grade + koubei pages are UTF-8. */
export async function ahFetch(url, contextHint) {
    let resp;
    try {
        resp = await fetch(url, {
            headers: {
                'User-Agent': UA,
                Referer: `${AH_BASE}/`,

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Check whether the source page truly contains the field (open the URL manually)
  2. Retry the fetch in case the page failed to render fully
  3. Guard your own input with clean()/an emptiness check before calling

Example fix

// before
requireText(entry.title, 'name') // title undefined
// after
requireText(entry.title ?? 'Unknown', 'name')
Defensive patterns

Strategy: type-guard

Validate before calling

if (!String(value ?? '').trim()) {
  throw new Error(label + ' is empty');
}

Type guard

function hasText(v) {
  return String(v ?? '').trim().length > 0;
}

Try / catch

try {
  const name = requireText(value, 'name');
} catch (err) {
  if (err instanceof CommandExecutionError && /stable text value/.test(err.message)) {
    console.error('Field was empty on the page; supply a fallback or retry');
  } else throw err;
}

Prevention

When it happens

Trigger: A scraped field missing on the page (e.g. no name/title rendered), passing null/'' from a failed lookup, or a whitespace-only value.

Common situations: Autohome page variants omitting a field; anti-bot or empty shell pages; upstream data absent for niche entities.

Understand the failure class

Background: "Missing required field" and "field is required" errors: why libraries reject payloads that omit mandatory fields — this error's family across 20 libraries.

Related errors


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