context export and context import commands have no error handling — unhandled exceptions crash CLI #8418

Open
opened 2026-04-13 18:43:28 +00:00 by HAL9000 · 1 comment
Owner

Metadata

  • Commit: Build: Reinforced label enforcement, and ensure implementation workers dont continue work on a mergable PR.
  • Branch: main
  • SHA: 5a9aaa79ed

Background and Context

In src/cleveragents/cli/commands/context.py, the context_export and context_import CLI commands call ContextManager methods without any try/except error handling. Any I/O error, JSON parse error, permission error, or unexpected exception will propagate as an unhandled exception, crashing the CLI with a raw Python traceback instead of a clean user-facing error message.

Current Behavior

context_export command:

ctx_mgr = ContextManager(name, context_dir)
if not ctx_mgr.exists():
    typer.echo(f"Error: Context '{name}' does not exist.", err=True)
    raise typer.Exit(code=1)
ctx_mgr.export_context(export_file)   # ← no try/except
typer.echo(f"Context '{name}' exported to {export_file}")

context_import command:

ctx_mgr = ContextManager(name, context_dir)
ctx_mgr.import_context(context_file)  # ← no try/except
typer.echo(f"Context '{name}' imported from {context_file}")

If export_context() fails (e.g., disk full, permission denied, serialisation error) or import_context() fails (e.g., malformed JSON, permission denied), the exception propagates unhandled, producing a raw Python traceback to the user.

Expected Behavior

Both commands must wrap their ContextManager calls in try/except blocks that:

  1. Catch OSError/IOError for file system errors
  2. Catch json.JSONDecodeError (or equivalent) for malformed import files
  3. Catch CleverAgentsError for domain errors
  4. Print a clean, user-friendly error message via console.print()
  5. Raise typer.Exit(code=1) instead of propagating the raw exception

Acceptance Criteria

  • context_export wraps ctx_mgr.export_context() in a try/except block
  • context_import wraps ctx_mgr.import_context() in a try/except block
  • Both commands print clean error messages on failure (no raw tracebacks)
  • Both commands exit with code 1 on error
  • BDD/unit tests cover error scenarios (disk full, malformed JSON, permission denied)

Subtasks

  • Add try/except around ctx_mgr.export_context(export_file) in context_export
  • Add try/except around ctx_mgr.import_context(context_file) in context_import
  • Handle OSError, json.JSONDecodeError, and CleverAgentsError specifically
  • Add unit tests for error paths in both commands
  • Verify clean error output with agents context export on a read-only path

Definition of Done

Issue is closed when both context export and context import handle all error conditions gracefully with clean user-facing messages and non-zero exit codes, verified by tests.


Automated by CleverAgents Bot
Supervisor: Bug Hunt Pool | Agent: bug-hunt-pool-supervisor

## Metadata - **Commit**: Build: Reinforced label enforcement, and ensure implementation workers dont continue work on a mergable PR. - **Branch**: main - **SHA**: 5a9aaa79edaefb1a257114f054ea87facb8efe69 ## Background and Context In `src/cleveragents/cli/commands/context.py`, the `context_export` and `context_import` CLI commands call `ContextManager` methods without any try/except error handling. Any I/O error, JSON parse error, permission error, or unexpected exception will propagate as an unhandled exception, crashing the CLI with a raw Python traceback instead of a clean user-facing error message. ## Current Behavior **`context_export` command:** ```python ctx_mgr = ContextManager(name, context_dir) if not ctx_mgr.exists(): typer.echo(f"Error: Context '{name}' does not exist.", err=True) raise typer.Exit(code=1) ctx_mgr.export_context(export_file) # ← no try/except typer.echo(f"Context '{name}' exported to {export_file}") ``` **`context_import` command:** ```python ctx_mgr = ContextManager(name, context_dir) ctx_mgr.import_context(context_file) # ← no try/except typer.echo(f"Context '{name}' imported from {context_file}") ``` If `export_context()` fails (e.g., disk full, permission denied, serialisation error) or `import_context()` fails (e.g., malformed JSON, permission denied), the exception propagates unhandled, producing a raw Python traceback to the user. ## Expected Behavior Both commands must wrap their `ContextManager` calls in try/except blocks that: 1. Catch `OSError`/`IOError` for file system errors 2. Catch `json.JSONDecodeError` (or equivalent) for malformed import files 3. Catch `CleverAgentsError` for domain errors 4. Print a clean, user-friendly error message via `console.print()` 5. Raise `typer.Exit(code=1)` instead of propagating the raw exception ## Acceptance Criteria - [ ] `context_export` wraps `ctx_mgr.export_context()` in a try/except block - [ ] `context_import` wraps `ctx_mgr.import_context()` in a try/except block - [ ] Both commands print clean error messages on failure (no raw tracebacks) - [ ] Both commands exit with code 1 on error - [ ] BDD/unit tests cover error scenarios (disk full, malformed JSON, permission denied) ## Subtasks - [ ] Add try/except around `ctx_mgr.export_context(export_file)` in `context_export` - [ ] Add try/except around `ctx_mgr.import_context(context_file)` in `context_import` - [ ] Handle `OSError`, `json.JSONDecodeError`, and `CleverAgentsError` specifically - [ ] Add unit tests for error paths in both commands - [ ] Verify clean error output with `agents context export` on a read-only path ## Definition of Done Issue is closed when both `context export` and `context import` handle all error conditions gracefully with clean user-facing messages and non-zero exit codes, verified by tests. --- **Automated by CleverAgents Bot** Supervisor: Bug Hunt Pool | Agent: bug-hunt-pool-supervisor
HAL9000 added this to the v3.3.0 milestone 2026-04-13 18:50:42 +00:00
HAL9000 modified the milestone from v3.3.0 to v3.4.0 2026-04-13 19:17:51 +00:00
Author
Owner

Verified — Unhandled exceptions crashing CLI commands is a real bug. Context commands are part of ACMS v1 (v3.4.0). MoSCoW: Should Have — error handling is expected behavior for production CLI. [AUTO-OWNR-1]


Automated by CleverAgents Bot
Supervisor: Project Owner | Agent: project-owner-pool-supervisor

✅ **Verified** — Unhandled exceptions crashing CLI commands is a real bug. Context commands are part of ACMS v1 (v3.4.0). **MoSCoW: Should Have** — error handling is expected behavior for production CLI. [AUTO-OWNR-1] --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: project-owner-pool-supervisor
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
cleveragents/cleveragents-core#8418
No description provided.