{"record":{"id":"a5dab49b8a5bcc8f","repo":"jackwener/OpenCLI","slug":"chess-com-monthly-archive-payload-is-missing-games","errorCode":null,"errorMessage":"Chess.com monthly archive payload is missing games array","messagePattern":"Chess\\.com monthly archive payload is missing games array","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/chess/games.js","lineNumber":52,"sourceCode":"    func: async (kwargs) => {\n        const username = validateUsername(kwargs.username);\n        const limit = parseLimit(kwargs.limit);\n        const archivesList = await chessApi(`/player/${encodeURIComponent(username)}/games/archives`);\n        if (!Array.isArray(archivesList.archives)) {\n            throw new CommandExecutionError('Chess.com archives payload is missing archives array');\n        }\n        const archives = archivesList.archives.slice().reverse();\n        if (archives.length === 0) {\n            throw new EmptyResultError(`Chess.com has no game archives for ${username}`);\n        }\n        const rows = [];\n        for (let i = 0; i < archives.length && i < MAX_ARCHIVE_FETCHES && rows.length < limit; i++) {\n            if (typeof archives[i] !== 'string' || !archives[i].startsWith('https://api.chess.com/pub/player/')) {\n                throw new CommandExecutionError('Chess.com archives payload contains an unexpected archive URL');\n            }\n            const monthly = await chessApi(archives[i]);\n            if (!Array.isArray(monthly.games)) {\n                throw new CommandExecutionError('Chess.com monthly archive payload is missing games array');\n            }\n            const games = monthly.games.slice().reverse();\n            for (const g of games) {\n                rows.push(mapGameRow(g, username));\n                if (rows.length >= limit) break;\n            }\n        }\n        if (rows.length === 0) {\n            throw new EmptyResultError(`Chess.com has games archives for ${username} but no games in the most recent ${MAX_ARCHIVE_FETCHES} months`);\n        }\n        return rows.slice(0, limit);\n    },\n});\n\nexport const __test__ = { parseLimit };\n","sourceCodeStart":34,"sourceCodeEnd":68,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/chess/games.js#L34-L68","documentation":"Each monthly archive fetched via chessApi(archives[i]) must contain a games array. If the payload for a month lacks .games, the command throws CommandExecutionError, indicating the monthly endpoint response no longer matches the expected schema.","triggerScenarios":"The GET of a monthly archive URL (https://api.chess.com/pub/player/{u}/games/{yyyy}/{mm}) succeeds but the body has no games array — Chess.com schema change, an error body returned with 200, or an intermediate/proxy response.","commonSituations":"Chess.com API format changes; mocked API servers missing the games key; edge/CDN error pages returned with 200 status.","solutions":["curl the specific monthly archive URL and inspect the JSON structure","Pin to a known-good version of this library or patch the expected field if Chess.com renamed the key","Bypass proxies/VPN that may alter responses"],"exampleFix":"// before\nconst monthly = await chessApi(url);\n// after\nconst monthly = await chessApi(url);\nif (monthly && monthly.chess_games) { monthly.games = monthly.chess_games; } // adapt renamed field\nif (!Array.isArray(monthly.games)) throw new CommandExecutionError('missing games array');","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"function hasGames(p) { return p != null && typeof p === 'object' && Array.isArray(p.games); }","tryCatchPattern":"try {\n  await gamesCmd(username);\n} catch (e) {\n  if (/missing games array/.test(e.message)) {\n    // inspect the monthly payload; check Chess.com API for schema changes\n  } else throw e;\n}","preventionTips":["Spot-check monthly archive JSON structure with curl during API drift concerns","Pin library versions and read Chess.com API announcements","Ensure no middleware returns 200 error pages for api.chess.com"],"tags":["schema-validation","upstream-api","chess-com"],"backgroundTag":"schema-validation-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}