feat: Catch and print IO errors

This commit is contained in:
Leni Aniva 2024-10-08 00:17:31 -07:00
parent 2e1276c21c
commit 5e776a1b49
Signed by: aniva
GPG Key ID: 4D9B1C8D10EA4C50
1 changed files with 10 additions and 5 deletions

View File

@ -33,11 +33,16 @@ partial def loop : MainM Unit := do
-- Using `Lean.Json.compress` here to prevent newline
IO.println error.compress
| .ok command =>
let ret ← execute command
let str := match state.options.printJsonPretty with
| true => ret.pretty
| false => ret.compress
IO.println str
try
let ret ← execute command
let str := match state.options.printJsonPretty with
| true => ret.pretty
| false => ret.compress
IO.println str
catch e =>
let message ← e.toMessageData.toString
let error := Lean.toJson ({ error := "io", desc := message }: InteractionError)
IO.println error.compress
loop