jackwener/OpenCLI · error · CommandExecutionError

Jike notifications API returned a malformed user

Error message

Jike notifications API returned a malformed user

What it means

mapNotification validates each entry of an action item's `users` array when building a notification row from the Jike notifications API. If any element is null or not a plain object, the library throws CommandExecutionError because it cannot extract a screen name from it. This is a defensive guard against the API returning a shape that changed or contains placeholder entries.

Source

Thrown at clis/jike/notifications.js:64

}

function mapNotification(notification) {
    if (!notification || typeof notification !== 'object' || typeof notification.id !== 'string' || !notification.id) {
        throw new CommandExecutionError('Jike notifications API returned a malformed notification');
    }
    if (typeof notification.type !== 'string' || !notification.type) {
        throw new CommandExecutionError('Jike notifications API returned a notification without a type');
    }
    const actionItem = notification.actionItem;
    if (!actionItem || typeof actionItem !== 'object' || Array.isArray(actionItem)) {
        throw new CommandExecutionError('Jike notifications API returned a malformed action item');
    }
    if (!Array.isArray(actionItem.users)) {
        throw new CommandExecutionError('Jike notifications API returned a malformed users list');
    }
    const names = actionItem.users.map((user) => {
        if (!user || typeof user !== 'object') {
            throw new CommandExecutionError('Jike notifications API returned a malformed user');
        }
        return typeof user.screenName === 'string' ? user.screenName : '';
    }).filter(Boolean);
    const referenceItem = notification.referenceItem;
    const referenceContent = referenceItem && typeof referenceItem === 'object' && !Array.isArray(referenceItem)
        ? referenceItem.content
        : '';
    const time = typeof notification.createdAt === 'string'
        ? notification.createdAt
        : (typeof notification.updatedAt === 'string' ? notification.updatedAt : '');
    return {
        type: resolveActionLabel(notification, actionItem),
        user: names.join('、'),
        content: cleanContent(actionItem.content || referenceContent),
        time,
    };
}

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Log the raw notification JSON to identify which notification and which user entry is malformed
  2. Update the CLI/library to the latest version to pick up any schema compatibility fixes
  3. Patch the mapping code to skip or coalesce malformed user entries instead of throwing
  4. Retry later in case it was a transient server-side data issue; report to Jike if persistent

Example fix

// before
const names = actionItem.users.map((user) => {
  if (!user || typeof user !== 'object') {
    throw new CommandExecutionError('Jike notifications API returned a malformed user');
  }
  return typeof user.screenName === 'string' ? user.screenName : '';
}).filter(Boolean);
// after
const names = actionItem.users.map((user) =>
  user && typeof user === 'object' && typeof user.screenName === 'string' ? user.screenName : ''
).filter(Boolean);
Defensive patterns

Strategy: type-guard

Validate before calling

// pre-validate a notifications response before mapping
function hasValidUserArrays(body) {
  return Array.isArray(body?.data) && body.data.every((n) =>
    !n?.actionItem || n.actionItem == null || Array.isArray(n.actionItem.users));
}

Type guard

function isUser(u) {
  return u !== null && typeof u === 'object' && !Array.isArray(u);
}

Try / catch

try {
  const rows = await cli('jike', 'notifications').run();
} catch (e) {
  if (String(e.message).includes('malformed user')) {
    // fall back to raw API fetch and lenient manual mapping
  } else throw e;
}

Prevention

When it happens

Trigger: The Jike notifications endpoint returns a notification whose actionItem.users array contains a null entry, a string/number instead of a user object, or the users field shape changes in a new API version while remaining an array.

Common situations: Jike changes its notification payload schema; deleted/suspended users appear as null placeholders in action lists; a proxy or cached response truncates/mangles user objects; running an older CLI against a newer API version.

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/0dfe96c7723d81ff. Report an issue: GitHub.