jackwener/OpenCLI · warning · EmptyResultError

nowcoder ${source}

Error message

nowcoder ${source}

What it means

After projecting all rows, projectNowcoderFeed throws EmptyResultError when zero posts survived, using `nowcoder ${source}` as the scope and the message 'Nowcoder returned no content or moment posts.' This distinguishes 'the feed worked but is empty' from malformed-data errors, letting callers handle emptiness (e.g., print 'no posts' or try another source) distinctly from hard failures.

Source

Thrown at clis/nowcoder/posts.js:173

        return {
            ...commonFeedFields(data, post, 'moment', post.userId, post.createdAt, index),
            id: uuid,
            uuid,
            entity_id: entityId,
            url: `https://www.nowcoder.com/feed/main/detail/${uuid}`,
        };
    }
    throw new CommandExecutionError(`Nowcoder returned unsupported feed contentType ${String(data.contentType)}`);
}

export function projectNowcoderFeed(records, limit, source, wrapped = false) {
    if (!Array.isArray(records)) throw new CommandExecutionError(`Nowcoder ${source} returned malformed records`);
    const rows = [];
    for (const record of records) {
        const data = wrapped ? record?.data : record;
        rows.push(projectFeedData(data, rows.length, source === 'experience' || wrapped));
    }
    if (rows.length === 0) throw new EmptyResultError(`nowcoder ${source}`, 'Nowcoder returned no content or moment posts.');
    return rows.slice(0, limit);
}

export function parseNowcoderPostTarget(raw) {
    const value = typeof raw === 'string' ? raw.trim() : '';
    if (NUMERIC_ID_PATTERN.test(value)) return { post_type: 'content', value };
    if (UUID_PATTERN.test(value)) return { post_type: 'moment', value: value.toLowerCase() };

    let url;
    try {
        url = new URL(value);
    }
    catch {
        throw new ArgumentError('nowcoder detail requires a numeric content ID, moment UUID, or canonical Nowcoder URL');
    }
    const host = url.hostname.toLowerCase();
    if (url.protocol !== 'https:' || url.username || url.password || url.port || url.hash
        || (host !== 'nowcoder.com' && host !== 'www.nowcoder.com')) {

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Catch EmptyResultError and treat it as a normal empty state rather than a failure.
  2. Try another feed source (e.g., 'recommend' instead of 'experience') or broaden query filters.
  3. Check that your pre-filtering did not remove every row before projection.
  4. Verify pagination parameters — request page 1 or fewer items if you walked past the end.

Example fix

// before
const rows = projectNowcoderFeed(records, 10, 'experience');
// after
let rows;
try {
    rows = projectNowcoderFeed(records, 10, 'experience');
} catch (error) {
    if (error instanceof EmptyResultError) rows = [];
    else throw error;
}
Defensive patterns

Strategy: try-catch

Validate before calling

if (Array.isArray(records) && records.length === 0) {
    // handle empty feed up front instead of calling projection
    return [];
}

Try / catch

import { EmptyResultError } from '@jackwener/opencli/errors';
try {
    rows = projectNowcoderFeed(records, limit, source, wrapped);
} catch (error) {
    if (error instanceof EmptyResultError) {
        rows = []; // normal empty state, not a failure
    } else throw error;
}

Prevention

When it happens

Trigger: Calling projectNowcoderFeed with an empty records array, or a records array whose every element was filtered out / had an unsupported or malformed shape you pre-filtered, with a valid limit.

Common situations: A user's feed genuinely has no posts (new account, restrictive filters, wrong --limit range upstream); querying the 'experience' source for a user with no shared experiences; pagination walked past the last page; an over-aggressive pre-filter removed all rows.

Understand the failure class

Background: EmptyResultError / "no results found": when an API or scraper succeeds but returns zero rows — this error's family across 9 libraries.

Related errors


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