dymokomi/luced
Source of release 0.4.1
## The entry point contains no widget geometry or command wiring. It also catches an
## error that would otherwise close the window in silence and records a crash report.
from editor.options import Options
from editor.application import Editor
import workspace.paths as paths
from luce_std import files
pub func main(arguments: list[str]) -> int!:
let options = Options(arguments)
if options.help:
options.print_help()
return 0
run_editor(options) catch failure:
report_crash(options, failure.message)
return 1
return 0
func run_editor(options: Options) -> unit!:
with Editor(options) as editor:
editor.run()
## Print the failure and save it to <config>/crash.log — with the recent breadcrumb trail from
## luced.log folded in — so a window that closes on an error leaves a trace instead of vanishing.
## (An uncatchable trap never reaches here; for those the flushed luced.log is the only record,
## which is why the journal writes each breadcrumb to disk as it happens.)
func report_crash(options: Options, message: str) -> unit:
save_crash(options, message) catch failure:
print("luced closed unexpectedly:\n\n" + message)
print("could not write the crash log: " + failure.message)
func save_crash(options: Options, message: str) -> unit!:
var directory = options.config_directory
if directory == "":
directory = paths.join(files.home_directory(), ".luced")
files.ensure_directory(directory)
let log_path = paths.join(directory, "luced.log")
let trail = files.read_text(log_path, 200000) catch failure: recover ""
let report = "luced closed unexpectedly:\n\n" + message + "\n\nRecent activity (also in luced.log):\n" + trail + "\n"
print(report)
let crash_path = paths.join(directory, "crash.log")
files.write_text(crash_path, report)
# Record the crash in the running log too, so the two files agree.
files.write_text(log_path, trail + "[crash] " + message + "\n")
print("saved a crash report to " + crash_path)