Skip to content

Commit 05d8097

Browse files
fix: improve input validation and error handling in managed CLI
- Filter empty package strings and validate non-empty package list - Add case-insensitive networking type validation - Move client creation after validation to avoid unnecessary API calls - Add trailing newline to test file (PEP 8) Addresses feedback from CodeRabbit, Gemini, and Copilot reviewers. Co-authored-by: Mervin Praison <MervinPraison@users.noreply.github.com>
1 parent d36aae5 commit 05d8097

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/praisonai/praisonai/cli/commands/managed.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -505,23 +505,29 @@ def envs_update(
505505
praisonai managed envs update env_01AbCdEf --packages "numpy,pandas"
506506
praisonai managed envs update env_01AbCdEf --networking limited
507507
"""
508-
client = _get_client()
509508
kwargs = {}
510509

511510
if packages:
512-
pkg_list = [p.strip() for p in packages.split(",")]
511+
pkg_list = [p.strip() for p in packages.split(",") if p.strip()]
512+
if not pkg_list:
513+
typer.echo("Error: --packages must include at least one non-empty package name")
514+
raise typer.Exit(1)
513515
kwargs["packages"] = {"pip": pkg_list}
514516

515517
if networking:
516-
if networking not in ["full", "limited"]:
518+
networking_lower = networking.lower()
519+
if networking_lower not in ["full", "limited"]:
517520
typer.echo("Error: --networking must be 'full' or 'limited'")
518521
raise typer.Exit(1)
519-
kwargs["networking"] = {"type": networking}
522+
kwargs["networking"] = {"type": networking_lower}
520523

521524
if not kwargs:
522525
typer.echo("Nothing to update. Pass --packages or --networking.")
523526
raise typer.Exit(0)
524527

528+
# Get client only after validation and early-exit checks
529+
client = _get_client()
530+
525531
try:
526532
updated = client.beta.environments.update(env_id, **kwargs)
527533
typer.echo(f"Updated environment: {updated.id}")

src/praisonai/tests/unit/cli/test_managed_cli_destructive.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,4 +326,4 @@ def fake_import(name, *args, **kwargs):
326326
assert exc_info.value.exit_code == 1
327327
finally:
328328
if saved is not None:
329-
sys.modules['anthropic'] = saved
329+
sys.modules['anthropic'] = saved

0 commit comments

Comments
 (0)