{"record":{"id":"abff0622221352b3","repo":"jackwener/OpenCLI","slug":"google-scholar-search-returned-an-unexpected-paylo","errorCode":null,"errorMessage":"Google Scholar search returned an unexpected payload shape","messagePattern":"Google Scholar search returned an unexpected payload shape","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/google-scholar/search.js","lineNumber":63,"sourceCode":"          const citedText = normalize(container.querySelector('.gs_fl a[href*=\"cites\"]')?.textContent);\n          const cited = citedText.match(/(\\\\d+)/)?.[1] || '0';\n\n          results.push({\n            rank: results.length + 1,\n            title,\n            authors: authors.slice(0, 80),\n            source: source.slice(0, 60),\n            year,\n            cited,\n            url,\n          });\n          if (results.length >= ${limit}) break;\n        }\n        return { items: results, resultCount: resultCards.length };\n      })()\n    `);\n        if (!wrapper || typeof wrapper !== 'object' || !Array.isArray(wrapper.items)) {\n            throw new CommandExecutionError('Google Scholar search returned an unexpected payload shape');\n        }\n        if (wrapper.items.length === 0) {\n            if (Number(wrapper.resultCount) > 0) {\n                throw new CommandExecutionError('Google Scholar result cards were present but no rows could be extracted');\n            }\n            throw new EmptyResultError('google-scholar/search', 'Try a different query or check whether Google Scholar returned a CAPTCHA.');\n        }\n        return wrapper.items;\n    },\n});\n","sourceCodeStart":45,"sourceCodeEnd":74,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/google-scholar/search.js#L45-L74","documentation":"The `google-scholar search` command evaluates an in-page script that must return an object `{ items: [...], resultCount }`. This guard throws a CommandExecutionError when the evaluated wrapper is null, not an object, or its `items` is not an array — i.e. the browser evaluation itself failed rather than returning an empty result set.","triggerScenarios":"Calling `google-scholar search <query>` where `page.evaluate` returns null/undefined or a non-object: the evaluate string failed to execute (script error, sandbox/CSP block), the browser page was torn down, or the driver returned an unexpected serialization.","commonSituations":"Browser crashed or tab navigated mid-evaluation; headless environment where `page.evaluate` on a template string is unsupported/misconfigured; CSP or page state preventing script execution; driver/automation-library version mismatch changing evaluate return semantics.","solutions":["Re-run the command — transient browser/page-state failures usually succeed on retry.","Check the browser automation setup (headless browser installed, driver versions compatible).","If it reproduces on every query, inspect whether scholar.google.com is returning an error/CAPTCHA page that breaks the evaluate script, and update the command.","Catch CommandExecutionError and fall back to a different search backend."],"exampleFix":"// before\nconst wrapper = null; // page.evaluate returned undefined -> throws\n// after\nif (!wrapper || typeof wrapper !== 'object' || !Array.isArray(wrapper.items)) {\n  return []; // or retry the navigation before surfacing the error\n}","handlingStrategy":"retry","validationCode":null,"typeGuard":"const isSearchPayload = (w) => !!w && typeof w === 'object' && Array.isArray(w.items);","tryCatchPattern":"try {\n  return await run('google-scholar search', query);\n} catch (e) {\n  if (/unexpected payload shape/.test(e.message)) {\n    await sleep(2000); return await run('google-scholar search', query); // one retry\n  }\n  throw e;\n}","preventionTips":["Keep browser automation stack up to date.","Ensure the headless browser is healthy (no stale tabs/crashes) between runs.","Check for CAPTCHA pages before parsing when loops fail repeatedly."],"tags":["scraping","browser","payload-shape","google-scholar"],"backgroundTag":"unexpected-payload-shape","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}