affaan-m/ECC · error · Error

discussion is not an Announcement

Error message

discussion is not an Announcement

What it means

discussionFromEnvironment builds the discussion object purely from workflow-provided env vars, but only permits use when DISCUSSION_CATEGORY is exactly 'Announcements'. The throw enforces that the injected discussion actually lives in the Announcements category, since the script only posts receipts into announcements.

Solutions

  1. Set DISCUSSION_CATEGORY=Announcements in the workflow env
  2. Move the target discussion into the Announcements category
  3. Use the GitHub-lookup path instead by passing DISCUSSION_NUMBER for a discussion already in Announcements
  4. Trim/case-normalize the comparison if upstream providers vary the value

Example fix

// before
if (env.DISCUSSION_CATEGORY !== 'Announcements') throw new Error('discussion is not an Announcement');
// after
if (env.DISCUSSION_CATEGORY?.trim() !== 'Announcements') throw new Error(`discussion is not an Announcement (got: ${env.DISCUSSION_CATEGORY})`);
Defensive patterns

Strategy: validation

Validate before calling

// guard in the workflow before the script runs
if (process.env.DISCUSSION_CATEGORY !== 'Announcements') {
  throw new Error(`DISCUSSION_CATEGORY must be 'Announcements', got: ${process.env.DISCUSSION_CATEGORY}`);
}

Type guard

function isAnnouncementEnv(env) {
  return env.DISCUSSION_CATEGORY === 'Announcements'
    && typeof env.DISCUSSION_ID === 'string' && env.DISCUSSION_ID.length > 0;
}

Try / catch

try {
  const discussion = discussionFromEnvironment();
} catch (err) {
  if (err.message === 'discussion is not an Announcement') {
    console.error(`DISCUSSION_CATEGORY=${process.env.DISCUSSION_CATEGORY}; expected 'Announcements'`);
  }
  throw err;
}

Prevention

When it happens

Trigger: Env-provided path selected (DISCUSSION_ID etc. present) but DISCUSSION_CATEGORY env var holds any other value — e.g. 'General', 'Ideas', unset-and-defaulted, or differently cased like 'announcements'.

Common situations: Workflow step wired with DISCUSSION_ID/DISCUSSION_TITLE but forgot to pass DISCUSSION_CATEGORY; CI passes the category of an existing discussion that lives in a non-announcement category; case sensitivity mismatch.

Understand the failure class

Background: "is not a valid" / "Invalid ... value" environment variable errors: how libraries validate env vars and what to do when they reject yours — this error's family across 48 libraries.

Related errors


AI-assisted analysis of affaan-m/ECC@8321021c54 (2026-09-16). Data as JSON: /api/errors/3243fcda01984732. Report an issue: GitHub.

Appendix: source

Thrown at scripts/discord/release-announce.mjs:85

    const discussions = pageData.repository.discussions;
    existing = findReleaseDiscussion(discussions.nodes, marker);
    if (!discussions.pageInfo.hasNextPage) break;
    cursor = discussions.pageInfo.endCursor;
  }
  if (existing) return existing;
  const category = repository.discussionCategories.nodes.find(item => item.name === 'Announcements');
  if (!category) throw new Error('Announcements discussion category is required');
  const title = `${release.name || release.tag_name} release`;
  const body = [marker, release.body || '', `Release: ${release.html_url}`].filter(Boolean).join('\n\n');
  const created = await githubGraphql(
    `mutation($repo:ID!,$cat:ID!,$title:String!,$body:String!){createDiscussion(input:{repositoryId:$repo,categoryId:$cat,title:$title,body:$body}){discussion{id title body url category{name}}}}`,
    { repo: repository.id, cat: category.id, title, body },
  );
  return created.createDiscussion.discussion;
}

function discussionFromEnvironment() {
  if (env.DISCUSSION_CATEGORY !== 'Announcements') throw new Error('discussion is not an Announcement');
  return {
    id: env.DISCUSSION_ID,
    title: env.DISCUSSION_TITLE,
    body: env.DISCUSSION_BODY,
    url: env.DISCUSSION_URL,
  };
}

async function discussionFromGitHub() {
  if (!/^\d+$/.test(env.DISCUSSION_NUMBER || '')) throw new Error('discussion number is invalid');
  const response = await request(`https://api.github.com/repos/${env.GITHUB_REPOSITORY}/discussions/${env.DISCUSSION_NUMBER}`, {
    headers: { Authorization: `Bearer ${env.GITHUB_TOKEN}`, Accept: 'application/vnd.github+json' },
  });
  if (!response.ok) throw new Error(`discussion lookup failed (${response.status})`);
  const discussion = await response.json();
  if (discussion.category?.name !== 'Announcements') throw new Error('discussion is not an Announcement');
  return { id: discussion.node_id, title: discussion.title, body: discussion.body, url: discussion.html_url };
}

View on GitHub (pinned to 8321021c54)