jackwener/OpenCLI · error · CommandExecutionError

Zhihu collection returned a malformed item without title or

Error message

Zhihu collection returned a malformed item without title or URL identity

What it means

mapCollectionItem throws CommandExecutionError when a mapped collection item ends up with an empty title, an empty URL, or a URL containing 'undefined'. This guards against Zhihu returning items whose identity fields are missing, which would otherwise render as blank/broken listing rows.

Source

Thrown at clis/zhihu/collection.js:88

    url = content.url || `https://www.zhihu.com/question/${question.id}/answer/${content.id}`;
    author = content.author?.name || '匿名用户';
    votes = content.voteup_count || 0;
  } else if (type === 'article') {
    title = content.title || '';
    excerpt = stripHtml(content.content || '').substring(0, 150);
    url = content.url || `https://zhuanlan.zhihu.com/p/${content.id}`;
    author = content.author?.name || '匿名用户';
    votes = content.voteup_count || 0;
  } else if (type === 'pin') {
    title = '想法';
    excerpt = stripHtml((content.content || []).map((c) => c.content || '').join(' ')).substring(0, 150);
    url = content.url || `https://www.zhihu.com/pin/${content.id}`;
    author = content.author?.name || '匿名用户';
    votes = content.reaction_count || 0;
  }

  if (!String(title || '').trim() || !String(url || '').trim() || url.includes('undefined')) {
    throw new CommandExecutionError(
      'Zhihu collection returned a malformed item without title or URL identity',
      'Collection item rows require type, title, and URL so malformed payloads do not become blank listing rows.',
    );
  }

  return {
    rank,
    type,
    title: stripHtml(title).substring(0, 100),
    author,
    votes,
    excerpt,
    url,
  };
}

cli({
  site: 'zhihu',

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Re-authenticate so Zhihu returns full item payloads, then retry
  2. Update the CLI in case a newer mapper handles the new payload shape
  3. Retry later — often a transient degraded API response
  4. Log the raw item (with -v) and report a schema-drift bug if it reproduces

Example fix

// before
// mapper throws on blank title/url
// after
const items = raw.filter(it => it.content && it.content.title && it.content.id); // pre-filter malformed items before mapping
Defensive patterns

Strategy: validation

Validate before calling

const usable = rawItems.filter(it => {
  const t = String(it?.content?.title ?? it?.title ?? '').trim();
  const u = String(it?.content?.url ?? it?.url ?? '');
  return t && u && !u.includes('undefined');
});

Type guard

function hasItemIdentity(item) {
  const title = String(item?.content?.title ?? '').trim();
  const url = String(item?.content?.url ?? '').trim();
  return Boolean(title) && Boolean(url) && !url.includes('undefined');
}

Try / catch

try {
  return rawItems.map(mapCollectionItem);
} catch (e) {
  if (e.message.includes('malformed item')) return rawItems.filter(hasItemIdentity).map(mapCollectionItem);
  throw e;
}

Prevention

When it happens

Trigger: A collection item's content lacks title and its derived URL is empty or was built from a missing content.id (producing 'https://www.zhihu.com/pin/undefined'), typically because Zhihu's payload was truncated, redacted for unauthenticated views, or the item was deleted.

Common situations: Fetching a collection while partially logged out so Zhihu strips fields; deleted or shadow-banned content still listed in the collection; API returning partial items under anti-crawler degradation.

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/395b9245c6fe54a9. Report an issue: GitHub.