Skip to content

Don't crash/exit on errors in keybindings #12

@bjornbm

Description

@bjornbm

I think ple shouldn't exit when it encounters an error in an keybinding (or other areas that the editor api allow to be tweaked by ple_init). Since Lua has little safety, a small typo in a seldom-used corner of one's init file could lead to the loss of all “writing” done since last save, which could be extremely annoying. For a real world case, using my old ple_init (from when the buffer was still exposed) loads OK in PLE, but crashes to my shell prompt when I use a keybinding function using b, with the following stack trace:

^K                                       /Users/bjorn/.config/ple/ple_init.lua:20: attempt to index a nil value (local 'b')
stack traceback:
	/Users/bjorn/.config/ple/ple_init.lua:20: in function 'emacs_ctlk'
	/Users/bjorn/repos/ple/ple.lua:1085: in function </Users/bjorn/repos/ple/ple.lua:1070>
	[C]: in function 'xpcall'
	/Users/bjorn/repos/ple/ple.lua:1113: in local 'main'
	/Users/bjorn/repos/ple/ple.lua:1127: in main chunk
	[C]: in function 'dofile'
	/Users/bjorn/bin/ple:5: in main chunk
	[C]: in ?

I think ple should catch the error and display it it, but then return to the editor. Probably with a recommendation to save ASAP and restart PLE since the erroring function may have messed up state? Maybe even provide a prompt with three options:

  1. Save the buffer and exit.
  2. Write the current buffer contents to another file (add .saved to file name?) and exit. This is to preserve the last saved version and let the user do a manual merge. This is in case the user is worried the erroring function may have messed up the buffer state before the error, but they don't want to discard it completely and lose their work since last save.
  3. Continue (assume nothing is corrupted by the error and go on)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions