{"record":{"id":"8f42d00d38a5206e","repo":"jackwener/OpenCLI","slug":"question-not-found","errorCode":null,"errorMessage":"Question not found","messagePattern":"Question not found","errorType":"exception","errorClass":"EmptyResultError","httpStatus":null,"severity":"warning","filePath":"clis/stackoverflow/read.js","lineNumber":239,"sourceCode":"        { name: 'comments-limit', type: 'int', default: 5, help: 'Max comments per question/answer (1-100)' },\n        { name: 'max-length', type: 'int', default: 4000, help: 'Max characters per body / answer / comment (min 100)' },\n    ],\n    columns: ['type', 'author', 'score', 'accepted', 'text'],\n    func: async (args) => {\n        const id = String(args.id || '').trim();\n        if (!/^\\d+$/.test(id)) {\n            throw new ArgumentError(`Invalid Stack Overflow question id: ${args.id}`, 'Pass a numeric id like 79935770');\n        }\n        const answersLimit = requireBoundedInt(args['answers-limit'] ?? 10, 1, SE_MAX_PAGE_SIZE, 'stackoverflow read --answers-limit');\n        const commentsLimit = requireBoundedInt(args['comments-limit'] ?? 5, 1, SE_MAX_PAGE_SIZE, 'stackoverflow read --comments-limit');\n        const maxLength = requireMinInt(args['max-length'] ?? 4000, 100, 'stackoverflow read --max-length');\n\n        const label = `stackoverflow/${id}`;\n        const qUrl = `${SE_API_BASE}/questions/${id}?site=${SE_SITE}&filter=withbody`;\n        const qData = await fetchJson(qUrl, label);\n        const question = (qData.items || [])[0];\n        if (!question) {\n            throw new EmptyResultError(label, 'Question not found');\n        }\n\n        // Fetch question comments and answers in parallel.\n        const [qCommentsData, answersData] = await Promise.all([\n            fetchJson(\n                `${SE_API_BASE}/questions/${id}/comments?site=${SE_SITE}&filter=withbody&order=asc&sort=creation&pagesize=${commentsLimit}`,\n                `${label}/comments`,\n            ),\n            fetchJson(\n                `${SE_API_BASE}/questions/${id}/answers?site=${SE_SITE}&filter=withbody&order=desc&sort=votes&pagesize=${answersLimit}`,\n                `${label}/answers`,\n            ),\n        ]);\n\n        const allAnswers = await fetchMissingAcceptedAnswer(question, answersData.items || [], label);\n        // Surface accepted answer first, then by score order.\n        const orderedAnswers = byAcceptedThenScoreDesc(question, allAnswers).slice(0, answersLimit);\n","sourceCodeStart":221,"sourceCodeEnd":257,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/stackoverflow/read.js#L221-L257","documentation":"EmptyResultError thrown by `stackoverflow read` when the Stack Exchange /questions/{id} endpoint returns a 200 envelope whose `items` array has no first element. The API does that instead of a 404 when a question id does not exist, was deleted, or is not visible to anonymous users. The CLI treats 'no items' as an empty result rather than a network failure, so the label tells you which lookup came back empty.","triggerScenarios":"Calling `stackoverflow read <id>` where <id> is a nonexistent question id, a deleted question, a closed/removed post, or an id from a different Stack Exchange site (e.g. a Server Fault id against site=stackoverflow).","commonSituations":"Copying an id from a Stack Exchange site other than stackoverflow; the question was deleted by moderators after you got the link; a typo in the id (e.g. dropped/extra digit); agents scraping old references to questions that have since been removed.","solutions":["Verify the question id by opening https://stackoverflow.com/questions/<id> in a browser; if it 404s or is deleted, use a different id.","Confirm the id comes from stackoverflow.com and not another Stack Exchange site (serverfault, superuser, etc.).","Re-derive the id by running `stackoverflow search <terms>` and picking a question from the results.","If you expect empty results sometimes, catch EmptyResultError in the calling script instead of treating it as a crash."],"exampleFix":"// before: blindly reading a scraped id\nawait cli.run(['stackoverflow', 'read', scrapedId]);\n// after: guard against non-numeric/absent ids and handle empty\nif (!/^\\d+$/.test(scrapedId ?? '')) return null;\ntry {\n  return await cli.run(['stackoverflow', 'read', scrapedId]);\n} catch (e) {\n  if (e.name === 'EmptyResultError') return null;\n  throw e;\n}","handlingStrategy":"try-catch","validationCode":"if (!/^\\d+$/.test(String(id ?? '').trim())) throw new Error(`not a numeric question id: ${id}`);","typeGuard":"function isNumericId(v) { return typeof v === 'string' ? /^\\d+$/.test(v.trim()) : Number.isInteger(v) && v > 0; }","tryCatchPattern":"try {\n  const q = await read(id);\n} catch (e) {\n  if (e.name === 'EmptyResultError') {\n    console.warn(`question ${id} not found or deleted`);\n    return null;\n  }\n  throw e;\n}","preventionTips":["Extract ids only from stackoverflow.com/questions/<id> URLs, not other SE sites.","Validate the id is numeric before calling.","Handle EmptyResultError as a normal 'not found' outcome in scripts, not a crash.","Re-check links from old data — SO questions do get deleted."],"tags":["empty-result","stack-overflow","http-404","cli"],"backgroundTag":"empty-result-set","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}