{"record":{"id":"7dfcaae3f36d986c","repo":"jackwener/OpenCLI","slug":"could-not-find-formatlabel-citation-link-for-re","errorCode":null,"errorMessage":"Could not find ${formatLabel} citation link for result ${index + 1}","messagePattern":"Could not find (.+?) citation link for result (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/google-scholar/cite.js","lineNumber":58,"sourceCode":"        if (!clicked?.ok) {\n            throw new CommandExecutionError(clicked?.reason || `Could not find search result at index ${index + 1}`);\n        }\n\n        await page.wait(2);\n\n        const formatMap = { bibtex: 'BibTeX', endnote: 'EndNote', refman: 'RefMan', refworks: 'RefWorks' };\n        const formatLabel = formatMap[format] || 'BibTeX';\n\n        const citeUrl = await page.evaluate(`(() => {\n            var links = document.querySelectorAll('#gs_cit a.gs_citi');\n            for (var i = 0; i < links.length; i++) {\n                if (links[i].textContent.trim() === '${formatLabel}') return links[i].href;\n            }\n            return null;\n        })()`);\n\n        if (!citeUrl) {\n            throw new CommandExecutionError(`Could not find ${formatLabel} citation link for result ${index + 1}`);\n        }\n\n        await page.goto(citeUrl);\n        await page.wait(2);\n\n        const citation = await page.evaluate(`(() => {\n            return (document.body.innerText || '').trim();\n        })()`);\n\n        if (!citation) {\n            throw new CommandExecutionError(`${formatLabel} citation page returned an empty response`);\n        }\n\n        return [{ title: clicked.title, format: format, citation }];\n    },\n});\n","sourceCodeStart":40,"sourceCodeEnd":75,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/google-scholar/cite.js#L40-L75","documentation":"After opening the Cite popup, the script scans the citation links for one whose text equals the requested format label (BibTeX, EndNote, RefMan, RefWorks); if none matches, it throws CommandExecutionError `Could not find ${formatLabel} citation link for result ${index+1}`. Unknown format values default to 'BibTeX' via formatMap, so this mainly fires when the popup did not contain the expected link.","triggerScenarios":"The cite popup failed to open or was empty for the chosen result; Google Scholar rendered a different popup layout; the popup's links hadn't loaded when evaluate ran (only a 2s wait precedes it).","commonSituations":"Requesting formats on result types lacking them; rate limiting producing a degraded popup; timing issues on slow connections where the 2s wait is insufficient.","solutions":["Retry — popup load timing is often transient; add extra wait before citing","Use the default 'bibtex' format, which is always present in the popup","Slow down / solve any CAPTCHA if Scholar is throttling you","Update the library if Scholar changed the cite popup markup"],"exampleFix":"// before\nawait scholarCite(page, 0, 'refworks'); // may not exist\n// after\ntry { await scholarCite(page, 0, 'refworks'); }\ncatch (e) { if (/citation link/.test(e.message)) await scholarCite(page, 0, 'bibtex'); else throw e; }","handlingStrategy":"fallback","validationCode":"const supportedFormats = ['bibtex','endnote','refman','refworks'];\nif (!supportedFormats.includes(format)) format = 'bibtex';","typeGuard":"const isCiteFormat = (f) => ['bibtex','endnote','refman','refworks'].includes(f);","tryCatchPattern":"try { out = await scholarCite(page, i, fmt); }\ncatch (e) { if (/citation link/.test(e.message)) out = await scholarCite(page, i, 'bibtex'); else throw e; }","preventionTips":["Fall back to bibtex, which is always present in the cite popup","Add extra wait after clicking Cite on slow connections","Throttle request rate to avoid degraded Scholar responses"],"tags":["google-scholar","citation","ui-automation"],"backgroundTag":"element-not-found","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}