Skip to content

fix(hello): validate login inputs with actionable hints#24

Merged
facundofarias merged 1 commit into
mainfrom
fix/hello-clearer-missing-api-key
Jun 8, 2026
Merged

fix(hello): validate login inputs with actionable hints#24
facundofarias merged 1 commit into
mainfrom
fix/hello-clearer-missing-api-key

Conversation

@facundofarias

@facundofarias facundofarias commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Summary

dhq hello shows a small but persistent deployhq: api key is required bucket on Mixpanel (2 hits / 30d on v0.18.x). The masked API-key prompt accepts an empty Enter, then sdk.New surfaces its internal validation string verbatim. Users see a cryptic deployhq:-prefixed message with no guidance on where to find the key.

  • internal/commands/hello.go — new validateHelloLoginInputs(account, email, apiKey) runs after the prompts and before sdk.New, returning a UserError per missing field. Each error has a hint that points at the source of that value; the API-key hint names the DeployHQ UI path ("Profile → API Key") and tells the user to re-run dhq hello. Headlines drop the deployhq: prefix so the new telemetry buckets are immediately readable.
  • internal/commands/hello_test.go — five table-driven cases: success path, each missing-field branch, and first-failure-wins ordering (so users only fix one thing at a time). Headline assertions go through strings.SplitN(err.Error(), "\n", 2)[0] to mirror what telemetry.SanitizeErrorMessage actually sees.

What this doesn't try to do

  • Re-prompt on empty input: would be nicer UX but adds loop logic in interactive code that's hard to test. The current dhq hello is short enough that a re-run is cheap, and the explicit hint covers the path.

Test plan

  • go test ./... — all packages green
  • golangci-lint run ./... — 0 issues
  • Tests cover ok / 3× missing-field / ordering branches; headline assertions match telemetry's first-line behaviour

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Improved input validation with clearer, field-specific error messages when account, email, or API key is missing or invalid.
  • Tests

    • Added comprehensive test coverage for input validation scenarios.

Telemetry on v0.18.x shows a small but persistent "deployhq: api key
is required" bucket on `dhq hello` (2 hits / 30d). The cause: the
masked API-key prompt accepts an empty Enter, then sdk.New surfaces
the SDK's internal validation message verbatim — users see a cryptic
"deployhq:" prefixed string with no guidance on where to find the key.

- New validateHelloLoginInputs runs after the prompts and before
  sdk.New, returning a UserError per missing field with a hint that
  points at the source of each value. The API-key hint names the
  DeployHQ UI path ("Profile → API Key") and tells users to re-run
  the command.
- The headline strings ("Account is required" / "Email is required" /
  "API key is required") drop the "deployhq:" SDK prefix so the new
  telemetry buckets are immediately recognisable.
- Five test cases cover the success path, each missing-field branch,
  and the first-failure-wins ordering so users fix one thing at a time.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 8, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3f45442c-bcde-477b-a85b-26abd0a02f47

📥 Commits

Reviewing files that changed from the base of the PR and between 82c1e4e and ac371e8.

📒 Files selected for processing (2)
  • internal/commands/hello.go
  • internal/commands/hello_test.go

Walkthrough

The PR adds early input validation to the hello login command. A new validateHelloLoginInputs helper function checks that account, email, and API key fields are non-empty and returns field-specific user error messages with guidance hints. The validation is called at the start of helloLogin before any SDK operations, ensuring invalid inputs fail fast with clear user-facing feedback instead of propagating raw SDK errors downstream.

Changes

Hello login input validation

Layer / File(s) Summary
Input validation helper
internal/commands/hello.go
validateHelloLoginInputs checks account, email, and API key for empty values and returns *output.UserError with specific messages and field-specific hints; returns nil for valid inputs.
Validation integration into helloLogin
internal/commands/hello.go
helloLogin calls validateHelloLoginInputs immediately after trimming inputs, returning early with a user error when validation fails, before proceeding to SDK credential operations.
Validation tests
internal/commands/hello_test.go
New TestValidateHelloLoginInputs table-driven test validates behavior across valid inputs, missing fields, and priority scenarios; imports strings for test helper utilities.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding input validation for the hello command with user-friendly error hints.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/hello-clearer-missing-api-key

Comment @coderabbitai help to get the list of available commands and usage tips.

@facundofarias facundofarias merged commit 65bd97d into main Jun 8, 2026
3 checks passed
@facundofarias facundofarias deleted the fix/hello-clearer-missing-api-key branch June 8, 2026 09:19
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