fix: validate name argument in admin create/delete commands#398
fix: validate name argument in admin create/delete commands#398raballew wants to merge 1 commit intojumpstarter-dev:mainfrom
Conversation
The admin delete client/exporter and create client/exporter commands crashed with a Python traceback when invoked without a name argument. Adds a shared validate_name() helper in jumpstarter_cli_common.opt that raises a clear UsageError with the message "Missing required argument 'NAME'" when name is None, empty, or whitespace-only. Closes jumpstarter-dev#364 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
❌ Deploy Preview for jumpstarter-docs failed. Why did it fail? →
|
📝 WalkthroughWalkthroughInput validation was added to prevent executing create and delete commands without a name parameter. A new Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
python/packages/jumpstarter-cli-common/jumpstarter_cli_common/opt.py (1)
116-119: Consider normalizingNAMEbefore returning fromvalidate_name.Right now, surrounding whitespace is accepted (e.g.
" my-client "), which can still defer failure to server-side validation. Returning a stripped value fromvalidate_namewould keep this class of input handling fully client-side.♻️ Proposed refactor
-def validate_name(name: Optional[str]) -> None: - if not name or not name.strip(): +def validate_name(name: Optional[str]) -> str: + normalized = (name or "").strip() + if not normalized: raise click.UsageError("Missing required argument 'NAME'.") + return normalizedThen at call sites:
-validate_name(name) +name = validate_name(name)🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@python/packages/jumpstarter-cli-common/jumpstarter_cli_common/opt.py` around lines 116 - 119, The validate_name function currently only checks for missing/blank names but accepts surrounding whitespace; change validate_name(name: Optional[str]) to return the normalized (stripped) name (update signature to -> str), perform the existing empty check on name.strip(), and return name.strip(); then update all call sites that previously relied on validate_name for side-effects to capture the returned value (e.g., use name = validate_name(name)) so callers work with the normalized NAME going forward.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@python/packages/jumpstarter-cli-common/jumpstarter_cli_common/opt.py`:
- Around line 116-119: The validate_name function currently only checks for
missing/blank names but accepts surrounding whitespace; change
validate_name(name: Optional[str]) to return the normalized (stripped) name
(update signature to -> str), perform the existing empty check on name.strip(),
and return name.strip(); then update all call sites that previously relied on
validate_name for side-effects to capture the returned value (e.g., use name =
validate_name(name)) so callers work with the normalized NAME going forward.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: d3a9e2cc-c7f4-49f3-8bf6-54a752c6e4c3
📒 Files selected for processing (4)
python/packages/jumpstarter-cli-admin/jumpstarter_cli_admin/create.pypython/packages/jumpstarter-cli-admin/jumpstarter_cli_admin/delete.pypython/packages/jumpstarter-cli-common/jumpstarter_cli_common/opt.pypython/packages/jumpstarter-cli-common/jumpstarter_cli_common/opt_test.py
Summary
jmp admin delete client/exporterandjmp admin create client/exportercrashed with a raw Python traceback when invoked without a name argumentvalidate_name()helper injumpstarter_cli_common.optthat raises a clearUsageError("Missing required argument 'NAME'.")when name is None, empty, or whitespace-onlycreate.pyanddelete.pyimport and use the shared helperTest plan
validate_namein cli-common (None, empty, whitespace, valid name)Closes #364
🤖 Generated with Claude Code