jackwener/OpenCLI · error · CommandExecutionError

Chess.com stats payload for ${kind}.record is not an object

Error message

Chess.com stats payload for ${kind}.record is not an object

What it means

summarizeStats() validates that k.record (win/loss/draw counts) is either absent/null or a plain object. This throw fires when k.record exists but is not a plain object. Unlike last/best, record defaults to {} when missing, but a wrong-typed present value is rejected so wins/losses/draws extraction is well-defined.

Source

Thrown at clis/chess/utils.js:82

    }
    return payload;
}

/** Pull rating + record fields out of a stats sub-object (`chess_rapid` etc). */
export function summarizeStats(stats, kind) {
    const k = stats?.[kind];
    if (!k) return null;
    if (!isPlainObject(k)) {
        throw new CommandExecutionError(`Chess.com stats payload for ${kind} is not an object`);
    }
    if (!isOptionalPlainObject(k.last)) {
        throw new CommandExecutionError(`Chess.com stats payload for ${kind}.last is not an object`);
    }
    if (!isOptionalPlainObject(k.best)) {
        throw new CommandExecutionError(`Chess.com stats payload for ${kind}.best is not an object`);
    }
    if (!isOptionalPlainObject(k.record)) {
        throw new CommandExecutionError(`Chess.com stats payload for ${kind}.record is not an object`);
    }
    const record = isPlainObject(k.record) ? k.record : {};
    return {
        kind: kind.replace(/^chess_/, ''),
        rating_current: k.last?.rating ?? '',
        rating_best: k.best?.rating ?? '',
        wins: record.win ?? '',
        losses: record.loss ?? '',
        draws: record.draw ?? '',
    };
}

/** Parse an end_time epoch (seconds) into YYYY-MM-DD. */
export function formatDate(epochSeconds) {
    if (!epochSeconds || typeof epochSeconds !== 'number') return '';
    return new Date(epochSeconds * 1000).toISOString().slice(0, 10);
}

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Re-fetch the stats from the pub API; record must be an object like { win: 10, loss: 5, draw: 2 }
  2. Fix whatever serialized the record into a string/array before calling summarizeStats
  3. Use record: { win: 0, loss: 0, draw: 0 } in fixtures instead of compact strings
  4. Update the mapping if Chess.com reshaped the record field

Example fix

// before
stats.chess_rapid.record = '10-5-2';
// after
stats.chess_rapid.record = { win: 10, loss: 5, draw: 2 };
Defensive patterns

Strategy: validation

Validate before calling

const record = stats?.[kind]?.record;
if (record != null && (typeof record !== 'object' || Array.isArray(record))) {
  throw new Error(`${kind}.record must be an object like { win, loss, draw }`);
}

Type guard

function hasValidRecord(k) {
  return k?.record == null ||
    (typeof k.record === 'object' && !Array.isArray(k.record) &&
      ['win', 'loss', 'draw'].every((key) => key in k.record));
}

Try / catch

try {
  const row = summarizeStats(stats, 'chess_rapid');
} catch (err) {
  if (String(err.message).includes('.record is not an object')) {
    console.warn('record malformed; W/L/D columns will be skipped');
  } else { throw err; }
}

Prevention

When it happens

Trigger: stats[kind].record is a truthy non-object — e.g. record: "10/5/2" or record: [10,5,2] — in the payload flowing through rows() or row().

Common situations: Aggregation code stringified the W/L/D record; a cached payload from a differently-shaped source; test fixtures built with compact record notation; upstream schema change on the Chess.com stats endpoint.

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