Skip to content

addPromptToSet still throws — plan-limit and validation errors surface as the masked digest toast #547

Closed

Description

@gkhngyk

Problem

addPromptToSet in web/src/lib/actions/prompt.ts still throws on user-reachable failures. In production, a thrown Next.js server action reaches the client as the masked An error occurred in the Server Components render… digest: … string — so the toast shows that instead of the real message.

Throw sites inside addPromptToSet:

  • Prompt set not found
  • enforceLimit(orgId, 'maxPrompts', …) → PlanLimitError when the plan's prompt cap is reached
  • At least one platform or model must be selected.
  • Supabase insert errors

Repro: on an org at its prompt cap, open Brand → Prompts and add a single prompt (manual add or bulk-save suggestions). The toast shows the digest string instead of the plan-limit message.

Fix

PR #536 already converted the sibling savePromptSet to return { promptSet } | { error: string; code?: 'plan_limit' } instead of throwing, and addPromptToBrand in the same file is the reference implementation — it carries a doc comment explaining exactly why errors must be returned as values.

  1. Change addPromptToSet to return { prompt: Prompt } | { error: string; code?: 'plan_limit' }. Catch PlanLimitError from enforceLimit and map it to code: 'plan_limit'.
  2. Update both call sites in web/src/app/[locale]/(dashboard)/dashboard/brands/[id]/prompts/page.tsx (bulk suggestion save + manual add). They already handle the savePromptSet result with an if ('error' in result) branch, so the same shape applies — the addPromptToSet calls sit right next to code that shows the pattern.

Acceptance

  • Hitting the plan cap via "Add prompt" shows the human-readable plan-limit message (never the digest string).
  • Deselecting all platforms/models shows At least one platform or model must be selected.

Activity

  1. added
    bug
    good first issue
    on Jul 28, 2026
  2. self-assigned this
    on Aug 1, 2026
  3. added a commit that references this issue on Aug 3, 2026
    3c9c214
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

buggood first issue

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions