Skip to content

Commit 81c734b

Browse files
authored
Fix: Handled and pretty-printed exceptions without exiting the CLI. (#2055)
1 parent 54fa1f7 commit 81c734b

File tree

1 file changed

+5
-0
lines changed
  • pydantic_ai_slim/pydantic_ai

1 file changed

+5
-0
lines changed

pydantic_ai_slim/pydantic_ai/_cli.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,11 @@ async def run_chat(
254254
messages = await ask_agent(agent, text, stream, console, code_theme, deps, messages)
255255
except CancelledError: # pragma: no cover
256256
console.print('[dim]Interrupted[/dim]')
257+
except Exception as e: # pragma: no cover
258+
cause = getattr(e, '__cause__', None)
259+
console.print(f'\n[red]{type(e).__name__}:[/red] {e}')
260+
if cause:
261+
console.print(f'[dim]Caused by: {cause}[/dim]')
257262

258263

259264
async def ask_agent(

0 commit comments

Comments
 (0)