feat: Catch and print IO errors in REPL #109
22
Main.lean
22
Main.lean
|
@ -33,11 +33,16 @@ partial def loop : MainM Unit := do
|
||||||
-- Using `Lean.Json.compress` here to prevent newline
|
-- Using `Lean.Json.compress` here to prevent newline
|
||||||
IO.println error.compress
|
IO.println error.compress
|
||||||
| .ok command =>
|
| .ok command =>
|
||||||
let ret ← execute command
|
try
|
||||||
let str := match state.options.printJsonPretty with
|
let ret ← execute command
|
||||||
| true => ret.pretty
|
let str := match state.options.printJsonPretty with
|
||||||
| false => ret.compress
|
| true => ret.pretty
|
||||||
IO.println str
|
| 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
|
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.
|
-- NOTE: A more sophisticated scheme of command line argument handling is needed.
|
||||||
-- Separate imports and options
|
-- Separate imports and options
|
||||||
if args == ["--version"] then do
|
if args == ["--version"] then do
|
||||||
println! s!"{Pantograph.version}"
|
IO.println s!"{Pantograph.version}"
|
||||||
return
|
return
|
||||||
|
|
||||||
Pantograph.initSearch ""
|
Pantograph.initSearch ""
|
||||||
|
@ -62,5 +67,6 @@ unsafe def main (args: List String): IO Unit := do
|
||||||
IO.println "ready."
|
IO.println "ready."
|
||||||
discard <| coreM.toIO coreContext coreState
|
discard <| coreM.toIO coreContext coreState
|
||||||
catch ex =>
|
catch ex =>
|
||||||
IO.println "Uncaught IO exception"
|
let message := ex.toString
|
||||||
IO.println ex.toString
|
let error := Lean.toJson ({ error := "io", desc := message }: InteractionError)
|
||||||
|
IO.println error.compress
|
||||||
|
|
Loading…
Reference in New Issue