Skip to content

fix(service): fail with SERVICE.BRANCH_NOT_FOUND when --branch names a branch the project does not have - #414

Merged
wmadden-electric merged 3 commits into
mainfrom
fix/unknown-branch
Nov 30, 2026
Merged

wmadden-electric merged 3 commits into
mainfrom
fix/unknown-branch

Conversation

@wmadden-electric

Copy link
Copy Markdown
Contributor

A service command given a --branch the project does not have now says the branch is missing. Before, it said the service was missing.

Take a mistyped production:

$ prisma service delete api --branch prodution --json
prisma@8.0.0-rc.36 With this change
service delete api --branch prodution SERVICE.SELECTION_INVALID: "The requested service does not exist in the resolved project", exit 2 SERVICE.BRANCH_NOT_FOUND, exit 2
service list --branch prodution an empty list, exit 0 SERVICE.BRANCH_NOT_FOUND, exit 2

The new error, as --json reports it:

{
  "code": "SERVICE.BRANCH_NOT_FOUND",
  "summary": "Project \"shop\" has no branch named \"prodution\"",
  "why": "Project \"shop\" (proj_1) has no branch named \"prodution\". The name may be mistyped, or the branch may have been deleted.",
  "nextActions": [
    { "kind": "user-choice", "label": "Pass --branch with the name of a branch the project has, or omit it to use the default branch." },
    { "kind": "run-command", "label": "List the project's branches", "command": "prisma branch list --project proj_1" }
  ],
  "meta": { "projectId": "proj_1", "branchName": "prodution" }
}

Breaking change for scripts: service list --branch <a branch that does not exist> used to print an empty list and exit 0. It now fails with exit code 2.

What went wrong before

Each project has branches, such as main or feature/login, and a service runs on one branch. A service command acts on the project's default branch, or on the branch --branch names.

#410 made the confirmation questions of destructive commands say "production" when they act on the default branch. To know that, every service command run with --branch now looks the name up in the project's branch list. When the list had no branch with that name, the CLI still went on with the name as typed. The management API then found no service on that branch, so the CLI reported a missing service, and service list reported no services.

The decision

When the lookup finds no branch with that name, the command stops at once with SERVICE.BRANCH_NOT_FOUND, before it lists or changes any service. The environment variable commands already do the same: prisma project env list --branch <missing> fails with PROJECT.ENV_BRANCH_NOT_FOUND.

service create is the one exception. Creating a service on a branch the project does not have creates that branch, so it still takes the name as typed. The check is on by default in the shared lookup, and service create turns it off with the acceptsUnlistedBranch option. A new service command therefore gets the check without having to ask for it.

A service named by its address is not affected. An address, such as @pr-42:shop.api, names the branch, the project and the service in one string. Its lookup already finds the branch, and reports its own error when the branch is missing.

The commands that now fail on a missing branch are service list, service show, service open, service logs, service delete, service version list, service version rollback, and service domain add, show, wait, retry and delete.

Tests

  • Against the fake management API, with --branch prodution on a project without that branch: service list, service delete and each of the five service domain commands fail with the new error, exit code 2 and the meta above, and make no request to list services. service delete also makes no delete request. The service list test checks the summary, why and the branch list next action word for word.
  • service create --branch <new> still creates the service on a new branch (an existing test).
  • A new real-API case runs service list --branch <missing> and checks the code and meta.
  • The fake API in the existing tests now lists the branches those tests name, such as staging and feature/foo, since an unlisted branch now fails.

Only the changed test files, the typecheck and lint were run locally. CI runs the rest.

Not in this pull request

postgres and bucket commands report a mistyped --branch badly too. They find branches through different code. The follow-up is one shared "find a branch by name" step for service, postgres, bucket and addresses. It is recorded here only, not yet in a ticket.

Alternatives considered

  • Look the branch up only after the service is not found, to explain the failure. The lookup already runs on every command with --branch, so this saves no request. And service list never fails to find a service, so it would still print an empty list.
  • For service list, warn and still exit 0. This avoids the breaking change. But a script that lists a mistyped branch would still read "no services" and act on it, which is the problem this change fixes.
  • Keep taking an unknown branch as typed in every command. Nothing breaks, but typos keep being reported as missing services.

Agent: amun-44

…RANCH_NOT_FOUND

Signed-off-by: willbot <w.a.madden+machine@gmail.com>
Signed-off-by: Will Madden <madden@prisma.io>
…the advice first

Signed-off-by: willbot <w.a.madden+machine@gmail.com>
Signed-off-by: Will Madden <madden@prisma.io>
Signed-off-by: willbot <w.a.madden+machine@gmail.com>
Signed-off-by: Will Madden <madden@prisma.io>
@coderabbitai

coderabbitai Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary by CodeRabbit

  • Bug Fixes
    • Service commands that use --branch now stop with a clear error when the branch does not exist in the project, rather than attempting to list or change services.
    • The error identifies the project and requested branch, and suggests using an existing branch or listing available branches. service create can still create a branch that is not yet listed.
  • Documentation
    • Updated the command guidance and error reference to explain branch validation and the service create exception.

Walkthrough

Service commands now reject a --branch name that is not listed in the project, returning SERVICE.BRANCH_NOT_FOUND before service operations. service create remains able to use an unlisted name. The change adds structured error details, documentation, and unit and end-to-end test coverage.

Merge Risk: Minimal · up to 83afc

Service commands now fail with a clear SERVICE.BRANCH_NOT_FOUND error when --branch names a branch that does not exist, and service create still works for new branches. The change is intentional, documented and tested. No concrete merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: service commands given a --branch absent from the project now fail with SERVICE.BRANCH_NOT_FOUND. The changeset (errors.ts, target.ts, service create opt-out, docs and…
Description check Passed The description matches the changeset. It explains the mistyped --branch problem, the new SERVICE.BRANCH_NOT_FOUND error and its JSON shape, the breaking change for service list, the service create ex…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: service commands given a --branch absent from the project now fail with SERVICE.BRANCH_NOT_FOUND. The changeset (errors.ts, target.ts, service create opt-out, docs and tests) matches this change directly. The title is long at 103 characters, but it is specific and accurate.

Full details: Description check

Explanation

The description matches the changeset. It explains the mistyped --branch problem, the new SERVICE.BRANCH_NOT_FOUND error and its JSON shape, the breaking change for service list, the service create exception, the affected commands, and the tests added. It is detailed and on topic.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
Simplify code

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 141be882-3f89-4790-b98c-65ce3cdb10dd
Commits

Reviewing files that changed from the base of the PR and between 619abb4 and 83afce5.

Files selected for processing: 10

  • docs/product/command-principles.md
  • docs/reference/error-reference.md
  • packages/cli/e2e/service.e2e.ts
  • packages/cli/src/commands/service/create.ts
  • packages/cli/src/commands/service/errors.ts
  • packages/cli/src/commands/service/target.ts
  • packages/cli/tests/service-delete.test.ts
  • packages/cli/tests/service-domain.test.ts
  • packages/cli/tests/service-list.test.ts
  • packages/cli/tests/service-testkit.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@wmadden-electric
wmadden-electric marked this pull request as ready for review November 30, 2026 00:49
@pkg-pr-new

pkg-pr-new Bot commented Nov 30, 2026

Copy link
Copy Markdown

Open in StackBlitz

npx https://pkg.pr.new/@prisma/cli@414
npx https://pkg.pr.new/@prisma/cli-engine@414

commit: 83afce5

@wmadden-electric
wmadden-electric merged commit f01594c into main Nov 30, 2026
16 checks passed
@wmadden-electric
wmadden-electric deleted the fix/unknown-branch branch November 30, 2026 00:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant