{"record":{"id":"93efc6e95d62be52","repo":"affaan-m/ECC","slug":"discussion-lookup-failed-response-status","errorCode":null,"errorMessage":"discussion lookup failed (${response.status})","messagePattern":"discussion lookup failed \\((.+?)\\)","errorType":"http","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/discord/release-announce.mjs","lineNumber":99,"sourceCode":"  return created.createDiscussion.discussion;\n}\n\nfunction discussionFromEnvironment() {\n  if (env.DISCUSSION_CATEGORY !== 'Announcements') throw new Error('discussion is not an Announcement');\n  return {\n    id: env.DISCUSSION_ID,\n    title: env.DISCUSSION_TITLE,\n    body: env.DISCUSSION_BODY,\n    url: env.DISCUSSION_URL,\n  };\n}\n\nasync function discussionFromGitHub() {\n  if (!/^\\d+$/.test(env.DISCUSSION_NUMBER || '')) throw new Error('discussion number is invalid');\n  const response = await request(`https://api.github.com/repos/${env.GITHUB_REPOSITORY}/discussions/${env.DISCUSSION_NUMBER}`, {\n    headers: { Authorization: `Bearer ${env.GITHUB_TOKEN}`, Accept: 'application/vnd.github+json' },\n  });\n  if (!response.ok) throw new Error(`discussion lookup failed (${response.status})`);\n  const discussion = await response.json();\n  if (discussion.category?.name !== 'Announcements') throw new Error('discussion is not an Announcement');\n  return { id: discussion.node_id, title: discussion.title, body: discussion.body, url: discussion.html_url };\n}\n\nasync function findReceiptComment(discussionId, marker) {\n  let cursor = null;\n  for (let page = 0; page < 50; page += 1) {\n    const data = await githubGraphql(\n      `query($id:ID!,$after:String){node(id:$id){... on Discussion{comments(first:100,after:$after){nodes{id body author{login}} pageInfo{hasNextPage endCursor}}}}}`,\n      { id: discussionId, after: cursor },\n    );\n    const comments = data.node?.comments;\n    if (!comments) throw new Error('discussion receipt lookup failed');\n    const receipt = findDiscussionReceipt(comments.nodes, marker);\n    if (receipt) return receipt;\n    if (!comments.pageInfo.hasNextPage) return null;\n    cursor = comments.pageInfo.endCursor;","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/scripts/discord/release-announce.mjs#L81-L117","documentation":"discussionFromGitHub throws this when the REST request GET /repos/{repo}/discussions/{number} returns a non-ok status. The status distinguishes 404 (no discussion with that number) from auth (401/403) and server errors.","triggerScenarios":"Discussion number points at a nonexistent discussion (404); GITHUB_TOKEN invalid or lacking repo scope (401/403); rate limited (403/429); the discussions REST endpoint unavailable for repos without discussions enabled (404/409 in some cases).","commonSituations":"Referring to a discussion by number in a different repository than GITHUB_REPOSITORY; discussion deleted; token scoped to another repo; enterprise/GHES versions lacking the discussions REST API.","solutions":["Confirm the discussion number exists in the same owner/repo as GITHUB_REPOSITORY (open the discussion URL and compare)","Check the status: 404 -> wrong number/repo or deleted discussion; 401/403 -> fix GITHUB_TOKEN and its repo scope","Ensure discussions are enabled for the repository","Log the response body for GitHub's detailed error"],"exampleFix":"// before\nif (!response.ok) throw new Error(`discussion lookup failed (${response.status})`);\n// after\nif (!response.ok) throw new Error(`discussion lookup failed (${response.status}): ${await response.text()}`);","handlingStrategy":"validation","validationCode":"// verify the discussion exists before the script\nconst res = await fetch(`https://api.github.com/repos/${process.env.GITHUB_REPOSITORY}/discussions/${process.env.DISCUSSION_NUMBER}`, { headers: { Authorization: `Bearer ${process.env.GITHUB_TOKEN}` } });\nif (!res.ok) throw new Error(`Discussion ${process.env.DISCUSSION_NUMBER} not reachable (${res.status}) — check repo, number, and token scope`);","typeGuard":null,"tryCatchPattern":"try {\n  const discussion = await discussionFromGitHub();\n} catch (err) {\n  const m = /discussion lookup failed \\((\\d+)\\)/.exec(err.message);\n  if (m && m[1] === '404') console.error('Discussion does not exist in this repo (or discussions disabled)');\n  if (m && ['401','403'].includes(m[1])) console.error('Check GITHUB_TOKEN validity and repo scope');\n  throw err;\n}","preventionTips":["Confirm the discussion belongs to the same GITHUB_REPOSITORY","Keep GITHUB_TOKEN valid with repo + read:discussion scopes","Ensure Discussions are enabled on the repository","Log the API response body for GitHub's detailed error message"],"tags":["github-api","http","rest"],"backgroundTag":"http-error-response","analyzedSha":"8321021c54d670126ce3b2969d5deb880b4b0c2a","analyzedAt":"2026-09-16T10:08:13.343Z","contentChangedAt":"2026-09-16T10:08:13.343Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}