{"record":{"id":"7f449f10bf1b3ce8","repo":"jackwener/OpenCLI","slug":"label-not-found","errorCode":null,"errorMessage":"${label} not found","messagePattern":"(.+?) not found","errorType":"exception","errorClass":"EmptyResultError","httpStatus":404,"severity":"warning","filePath":"clis/stackoverflow/read.js","lineNumber":41,"sourceCode":"import { ArgumentError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';\n\nconst SE_API_BASE = 'https://api.stackexchange.com/2.3';\nconst SE_SITE = 'stackoverflow';\nconst SE_MAX_PAGE_SIZE = 100;\n\nasync function fetchJson(url, label) {\n    let res;\n    try {\n        res = await fetch(url);\n    } catch (e) {\n        const detail = e instanceof Error ? e.message : String(e);\n        throw new CommandExecutionError(\n            `Network failure fetching ${label}: ${detail}`,\n            'Check connectivity to api.stackexchange.com',\n        );\n    }\n    if (res.status === 404) {\n        throw new EmptyResultError(label, `${label} not found`);\n    }\n    if (!res.ok) {\n        throw new CommandExecutionError(\n            `Stack Exchange API HTTP ${res.status} for ${label}`,\n            'Check the question id and quota (300/day per IP)',\n        );\n    }\n    let json;\n    try {\n        json = await res.json();\n    } catch (e) {\n        const detail = e instanceof Error ? e.message : String(e);\n        throw new CommandExecutionError(\n            `Malformed JSON from Stack Exchange API for ${label}: ${detail}`,\n            'The API returned a non-JSON body — likely a transient outage',\n        );\n    }\n    if (json && json.error_id) {","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/stackoverflow/read.js#L23-L59","documentation":"After the network request succeeds, fetchJson checks res.status === 404 and throws an EmptyResultError with the human-readable label. The Stack Exchange API answered, but the specific resource (question, answer, or comment set) does not exist or was not returned. It is an intentional 'nothing found' signal used by callers to render empty output rather than a crash.","triggerScenarios":"Calling qData with a question id that does not exist or was deleted; ansData/ansCommentsData/answersData with an answer id belonging to another (or deleted) question; passing a URL-extracted id that is actually a slug or truncated number; hitting a 404 because the site filter scoping excludes the item.","commonSituations":"Copy-pasting a question id from a different Stack Exchange site (e.g. Server Fault) while the CLI queries stackoverflow; id taken from a redirecting/merged question that now 404s; typo'd or partially copied id from a URL; question deleted by moderators after the script was written.","solutions":["Verify the question/answer id exists by opening stackoverflow.com/q/<id> in a browser","Confirm the id came from stackoverflow.com and not another Stack Exchange site","Re-extract the numeric id from the full URL (the digits before the slug)","If the question was deleted/merged, find its new id from the redirect page and retry"],"exampleFix":"// before\nawait readQuestion('58261800-slug');\n\n// after\nawait readQuestion('58261800');","handlingStrategy":"validation","validationCode":"function assertValidStackExchangeId(id, kind = 'question') {\n  const n = Number(String(id).trim());\n  if (!Number.isInteger(n) || n <= 0) {\n    throw new TypeError(`${kind} id must be a positive integer, got: ${id}`);\n  }\n  return n;\n}\n// call before: assertValidStackExchangeId(extractIdFromUrl(url));","typeGuard":"function isValidStackExchangeId(id) {\n  return typeof id === 'string'\n    ? /^\\d+$/.test(id.trim())\n    : Number.isInteger(id) && id > 0;\n}","tryCatchPattern":"import { EmptyResultError } from '@jackwener/opencli/errors';\n\ntry {\n  const q = await qData(id);\n} catch (e) {\n  if (e instanceof EmptyResultError) {\n    console.warn(`Skipping ${label}: not found or deleted`);\n  } else {\n    throw e;\n  }\n}","preventionTips":["Extract only the numeric portion of Stack Exchange URLs before passing ids","Confirm the id comes from stackoverflow.com, not another Stack Exchange site","Verify ids still resolve in a browser — questions get deleted or merged","Treat EmptyResultError as an expected, catchable 'no data' signal in scripts"],"tags":["http-404","not-found","stackexchange-api","bad-input"],"backgroundTag":"http-404-not-found","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}