cli/cli · error
failed to create discussion: %w
Error message
failed to create discussion: %w
What it means
A wrapper around discussionClient.Create failures that are total (the returned discussion is nil). Note the special case in the same block: if Create returns a non-nil discussion, the URL is printed to stdout, the raw error to stderr, and SilentError is returned instead - so this message only appears when nothing was created.
Source
Thrown at pkg/cmd/discussion/create/create.go:193
}
input := client.CreateDiscussionInput{
CategoryID: category.ID,
Title: opts.Title,
Body: opts.Body,
LabelIDs: labelIDs,
}
opts.IO.StartProgressIndicator()
discussion, err := c.Create(repo, input)
opts.IO.StopProgressIndicator()
if err != nil {
if discussion != nil {
fmt.Fprintln(opts.IO.Out, discussion.URL)
fmt.Fprintln(opts.IO.ErrOut, err.Error())
return cmdutil.SilentError
}
return fmt.Errorf("failed to create discussion: %w", err)
}
fmt.Fprintln(opts.IO.Out, discussion.URL)
return nil
}
View on GitHub (pinned to 0eeec0b92e)
Solutions
- Read the wrapped cause after the colon - it carries the real reason (e.g. 'repository has discussions disabled')
- Check auth: gh auth status
- Verify the category slug exists: gh api repos/OWNER/REPO/discussions/categories or re-run letting the CLI pick it
- If the discussion URL was printed to stdout, creation actually succeeded with partial failures - do not retry blindly (duplicate discussions)
Example fix
# before gh discussion create --title X --body Y --category nosuch # failed to create discussion: ... # after gh discussion create --title X --body Y # category picked interactively/validated
Defensive patterns
Strategy: try-catch
Validate before calling
// pre-flight the two common total-failure causes // 1) gh repo view -R owner/repo --json hasDiscussions -> must be true // 2) resolve category to a real slug before building input
Try / catch
discussion, err := c.Create(repo, input)
if err != nil {
if discussion != nil {
// URL already on stdout; log label failure, treat as success
return nil
}
return fmt.Errorf("creating discussion: %w", err) // inspect wrapped cause
} Prevention
- Unwrap the %w cause - the actionable reason is inside
- Watch stdout: a printed URL means creation succeeded (no retry -> avoids duplicates)
- Pre-check auth and category before creating in automation
When it happens
Trigger: gh discussion create where the createDiscussion mutation itself fails: repository discussions disabled (see 744), invalid category ID, permission denied, network/GraphQL errors. Label-only failures take the partial-success branch and never produce this message.
Common situations: Expired or scoped-down tokens; category resolved from stale cache; GitHub API incidents; discussions disabled on target repo.
Related errors
- limit argument must be positive: %v
- unknown order-by field: %q
- unknown order direction: %q
- unknown state filter: %q; should be one of %q, %q
- comment %s not found
AI-assisted analysis of cli/cli@0eeec0b92e (2026-08-15).
Data as JSON: /api/errors/4444df117d7eb7a6.
Report an issue: GitHub.