fix(deploy): explain "parent must exist" with actionable hint#23
Merged
Conversation
Telemetry shows a small but persistent "deployhq api: 422 parent must exist" bucket (5 hits / 30d on v0.18.1, all humans, all on `deploy`). The API enforces that a deployment's start_revision must trace back to a prior deployment's end_revision on the same target; when it can't, the CLI surfaces the raw Rails validation message which is opaque unless you've read the source. - New translateParentMustExistError detects the 422 + "parent must exist" combo from APIError.Message or .Errors and rewrites it as a UserError that names the actual start_revision SHA on the headline line (so telemetry's SanitizeErrorMessage preserves it) and offers --full or a corrected --start-revision in the Hint. - Apply at both deploy call sites (PreviewDeployment for --dry-run and CreateDeployment for the real path). - Four unit tests cover the .Message variant, the .Errors-array variant, the empty-start_revision rendering, and a passthrough table that locks in that unrelated errors stay untouched (nil, non-API, other 422 validation, the same string on a non-422). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
Disabled knowledge base sources:
WalkthroughDetects API HTTP 422 "parent must exist" validation errors during deploy preview/create, rewrites them into an actionable ChangesParent Must Exist Error Translation
sequenceDiagram
participant CLI as CLI (deploy command)
participant SDK as SDK client
participant API as API
CLI->>SDK: PreviewDeployment/CreateDeployment(req)
SDK->>API: HTTP request (deployment create/preview)
API-->>SDK: 422 validation error ("parent must exist")
SDK-->>CLI: sdk.APIError (422)
CLI->>CLI: translateParentMustExistError(err, start_revision)
CLI-->>User: output.UserError (translated message + hints)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~30 minutes 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
…t-exist-error # Conflicts: # internal/commands/deploy.go # internal/commands/deploy_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
dhq deploysurfaces a small-but-persistentdeployhq api: 422 parent must existbucket on Mixpanel (5 hits / 30d on v0.18.1, all humans, all ondeploy). The Rails Deployment model validates that the new deploy'sstart_revisiontraces back to a prior deployment'send_revisionon the same target. When it can't, the user sees an opaque message — they don't know what "parent" means, what SHA was sent, or that--fullwould bypass the issue.Two real-world causes:
LastRevisionstill points at it → incremental can't trace back.--start-revision(e.g. fromdhq repos commits), not realizing it must be a previously-deployed SHA, not any commit.What this PR does
internal/commands/deploy.go— newtranslateParentMustExistErrorhelper detects 422 + "parent must exist" on eitherAPIError.MessageorAPIError.Errors[]and rewrites it as aUserError. The actualstart_revisionSHA is in the headline line (sotelemetry.SanitizeErrorMessagepreserves it for the dashboard), and the Hint offers--fullor a corrected--start-revisionreferencingdhq deployments list. Wired into both call sites:PreviewDeployment(dry-run) andCreateDeployment.internal/commands/deploy_test.go— four unit tests:.Message.Errorsarray (the more common Rails shape)(none)so users can tell it was emptyWhat this PR deliberately doesn't do
--full: too magical; could surprise a user by deploying way more than intended.ListDeployments: adds an API call to every deploy for a small failure bucket; not worth it.start_revisionindhq deploy --dry-runoutput: separate UX improvement, easy follow-up if useful.Test plan
go test ./...— all packages greengolangci-lint run ./...— 0 issues.Messageand.Errors[]), the empty-SHA rendering, and passthrough behaviour🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Tests