Skip to content

fix(helpers): clearer error when project ID is missing#511

Draft
jacobwgillespie wants to merge 1 commit into
mainfrom
cursor/improve-missing-project-id-error-52a8
Draft

fix(helpers): clearer error when project ID is missing#511
jacobwgillespie wants to merge 1 commit into
mainfrom
cursor/improve-missing-project-id-error-52a8

Conversation

@jacobwgillespie
Copy link
Copy Markdown
Member

Summary

When depot build (or any caller of helpers.BeginBuild) is run without a project ID β€” no --project flag, no DEPOT_PROJECT_ID, and no depot.json β€” ResolveProjectID returns an empty string. We then sent an empty project_id to the NewBuild API, which responds with CodeNotFound. That triggered the interactive onboarding path (OnboardProject β†’ InitializeProject β†’ RetrieveProjects). In CI (notably depot/build-push-action with an OIDC token that has no list-projects scope), RetrieveProjects fails with:

Error: error retrieving projects: permission_denied: Not authorized

That message is misleading β€” it points users at authentication when the real fix is providing a project ID.

Change

In pkg/helpers/build.go, detect an empty req.ProjectId up front in BeginBuild (when we're not resuming via DEPOT_BUILD_ID) and return a clear, actionable error that lists all supported ways to configure a project:

no project ID specified. Please provide a project ID via the --project flag, the DEPOT_PROJECT_ID environment variable (the build-push-action sets this from its "project" input), or by adding a depot.json file to your project root (run "depot init")

This is exposed as ErrMissingProjectID so callers can errors.Is it if needed. All BeginBuild callers (build, bake, buildctl dial-stdio, exec) benefit automatically, including via depot/build-push-action which shells out to the CLI.

Test

Added pkg/helpers/build_test.go covering both the nil ProjectId pointer and an empty-string ProjectId, and asserting the message stays actionable.

=== RUN   TestBeginBuildReturnsClearErrorWhenProjectIDMissing
--- PASS: TestBeginBuildReturnsClearErrorWhenProjectIDMissing (0.00s)
PASS
ok  	github.com/depot/cli/pkg/helpers

Notes

The issue references depot/build-push-action@v1, but the error message itself originates in depot/cli (pkg/helpers/project.go:RetrieveProjects), and the issue is labeled depot/cli. Fixing it here means every caller of the CLI (including the GitHub Action, which shells out to depot build) gets the better message without an Action release.

Linear Issue: DEP-4447

Open in WebΒ Open in CursorΒ 

When a depot build is started without a project ID (no --project flag,
DEPOT_PROJECT_ID env var, or depot.json), BeginBuild used to call the
NewBuild API with an empty project_id. That returned CodeNotFound, which
triggered the OnboardProject -> RetrieveProjects path. In CI (e.g.
depot/build-push-action with an OIDC token that has no list-projects
scope) RetrieveProjects fails with 'permission_denied: Not authorized',
which is misleading: the real problem is the missing project ID, not
authentication.

Detect the empty project ID up front in BeginBuild and return a clear,
actionable error pointing at all the supported ways to configure a
project ID (CLI flag, env var, depot.json).

Fixes DEP-4447.

Co-authored-by: Jacob Gillespie <jacobwgillespie@gmail.com>
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.

2 participants