jackwener/OpenCLI · warning · EmptyResultError

No data for period "${period}". Available: ${Object.keys(dat

Error message

No data for period "${period}". Available: ${Object.keys(data.data).join(', ')}

What it means

An EmptyResultError thrown when the requested stats `period` key is absent from `data.data`. The response structure was valid, but there is no stats object for the period you asked for; the message lists which period keys the API actually returned. This turns a silent `undefined` into an actionable message.

Source

Thrown at clis/xiaohongshu/creator-stats.js:56

          const resp = await fetch('/api/galaxy/creator/data/note_detail_new', {
            credentials: 'include',
          });
          if (!resp.ok) return { error: 'HTTP ' + resp.status };
          return await resp.json();
        } catch (e) {
          return { error: e.message };
        }
      }
    `);
        if (data?.error) {
            throw new Error(data.error + '. Are you logged into creator.xiaohongshu.com?');
        }
        if (!data?.data) {
            throw new Error('Unexpected response structure');
        }
        const stats = data.data[period];
        if (!stats) {
            throw new EmptyResultError('xiaohongshu creator-stats', `No data for period "${period}". Available: ${Object.keys(data.data).join(', ')}`);
        }
        // Format daily trend as sparkline-like summary
        const formatTrend = (list) => {
            if (!list || !list.length)
                return '-';
            return list.map((d) => d.count).join(' → ');
        };
        return [
            { metric: '观看数 (views)', total: stats.view_count ?? 0, trend: formatTrend(stats.view_list) },
            { metric: '平均观看时长 (avg view time ms)', total: stats.view_time_avg ?? 0, trend: formatTrend(stats.view_time_list) },
            { metric: '主页访问 (home views)', total: stats.home_view_count ?? 0, trend: formatTrend(stats.home_view_list) },
            { metric: '点赞数 (likes)', total: stats.like_count ?? 0, trend: formatTrend(stats.like_list) },
            { metric: '收藏数 (collects)', total: stats.collect_count ?? 0, trend: formatTrend(stats.collect_list) },
            { metric: '评论数 (comments)', total: stats.comment_count ?? 0, trend: formatTrend(stats.comment_list) },
            { metric: '弹幕数 (danmaku)', total: stats.danmaku_count ?? 0, trend: '-' },
            { metric: '分享数 (shares)', total: stats.share_count ?? 0, trend: formatTrend(stats.share_list) },
            { metric: '涨粉数 (new followers)', total: stats.rise_fans_count ?? 0, trend: formatTrend(stats.rise_fans_list) },
        ];

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Use one of the period keys listed in the 'Available: ...' part of the message
  2. Check the accepted period values for this command and fix the typo
  3. If the key list looks wrong, log `Object.keys(data.data)` to inspect what the API returned
  4. Request a period range the account actually has data for

Example fix

// before
await getCreatorStats({ period: 'last7days' });
// after
await getCreatorStats({ period: '7d' }); // key must match one of the API's returned period keys
Defensive patterns

Strategy: validation

Validate before calling

const VALID_PERIODS = ['7d', '28d', '90d']; // use the keys the CLI/API documents
if (!VALID_PERIODS.includes(period)) {
  throw new Error(`Invalid period "${period}". Use one of: ${VALID_PERIODS.join(', ')}`);
}

Try / catch

try {
  const stats = await getCreatorStats({ period });
} catch (e) {
  if (e instanceof EmptyResultError || /No data for period/.test(e.message)) {
    const available = e.message.match(/Available: (.*)$/)?.[1] ?? '';
    // pick a valid key from `available` and retry
  } else { throw e; }
}

Prevention

When it happens

Trigger: Calling the creator-stats command with a period string that does not match any key in the returned data object (e.g. requesting a period the API does not provide for this account or date range).

Common situations: Typo in the period name; requesting a newer/older period than the account's data covers; Xiaohongshu renamed or removed period keys in its API.

Related errors


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