Merge pull request 'feat: Catch and print IO errors in REPL' (#109) from repl/io-exception into dev

Reviewed-on: #109
This commit is contained in:
Leni Aniva 2024-10-08 23:50:36 -07:00
commit 1cd41b4993
1 changed files with 14 additions and 8 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 := "main", desc := message }: InteractionError)
IO.println error.compress
loop
@ -45,7 +50,7 @@ unsafe def main (args: List String): IO Unit := do
-- NOTE: A more sophisticated scheme of command line argument handling is needed.
-- Separate imports and options
if args == ["--version"] then do
println! s!"{Pantograph.version}"
IO.println s!"{Pantograph.version}"
return
Pantograph.initSearch ""
@ -62,5 +67,6 @@ unsafe def main (args: List String): IO Unit := do
IO.println "ready."
discard <| coreM.toIO coreContext coreState
catch ex =>
IO.println "Uncaught IO exception"
IO.println ex.toString
let message := ex.toString
let error := Lean.toJson ({ error := "io", desc := message }: InteractionError)
IO.println error.compress