Skip to content

Commit 9921058

Browse files
authored
fix: improve CLI error messages in register and policy commands (#314)
The register command did a bare import of AgentIdentity inside the function body with no error handling. If agentmesh is not installed, Python dumps a raw traceback instead of a clear message. Wrapped the import in a try/except ImportError block that tells the user what to run. The policy command caught all exceptions as a single bare Exception and printed only the error object. Split it into FileNotFoundError, JSON/YAML parse errors, and a general fallback so each case gives a message that points to the actual problem. Related to issue #307.
1 parent a8d35fd commit 9921058

File tree

1 file changed

+10
-2
lines changed
  • packages/agent-mesh/src/agentmesh/cli

1 file changed

+10
-2
lines changed

packages/agent-mesh/src/agentmesh/cli/main.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,11 @@ def register(agent_dir: str, name: str = None):
258258
console.print(f"\n[bold blue]📝 Registering agent: {agent_name}[/bold blue]\n")
259259

260260
# Simulate registration
261-
from agentmesh.identity import AgentIdentity
261+
try:
262+
from agentmesh.identity import AgentIdentity
263+
except ImportError:
264+
console.print("[red]Error: agentmesh is not installed. Run: pip install agentmesh[/red]")
265+
return
262266
identity = AgentIdentity.create(agent_name)
263267

264268
console.print(f" [green]✓[/green] Generated identity: {identity.did}")
@@ -356,8 +360,12 @@ def policy(policy_file: str, validate: bool):
356360

357361
console.print(f"\n[green]Successfully loaded {len(policies)} policies[/green]")
358362

363+
except FileNotFoundError:
364+
console.print(f"[red]Error: Policy file not found: {policy_file}[/red]")
365+
except (json.JSONDecodeError, yaml.YAMLError) as e:
366+
console.print(f"[red]Error: Failed to parse {policy_file}{e}[/red]")
359367
except Exception as e:
360-
console.print(f"[red]Error: {e}[/red]")
368+
console.print(f"[red]Error loading policy: {e}[/red]")
361369

362370

363371
@app.command()

0 commit comments

Comments
 (0)