chrisant996 / clink-flex-prompt

Flex prompt for Clink

Repository from Github https://github.comchrisant996/clink-flex-promptRepository from Github https://github.comchrisant996/clink-flex-prompt

prompt broken if git repo is broken

Bananeweizen opened this issue · comments

My system crashed during a git pull. It left the repository in a somewhat broken state. That in turn leads to the prompt crashing. It would be nice to catch any exception in the prompt code, since otherwise all terminals are broken, and an uninstallation is the only way to get a working environment.

prompt filter failed:
C:\Users\userid\AppData\Local\clink\flexprompt.lua:1843: attempt to index local 'HEAD' (a nil value)
stack traceback:
        C:\Users\userid\AppData\Local\clink\flexprompt.lua:1843: in function 'get_git_branch'
        C:\Users\userid\AppData\Local\clink\flexprompt_modules.lua:779: in function 'func'
        C:\Users\userid\AppData\Local\clink\flexprompt.lua:1057: in function 'render_module'
        C:\Users\userid\AppData\Local\clink\flexprompt.lua:1127: in function 'render_modules'
        C:\Users\userid\AppData\Local\clink\flexprompt.lua:1222: in function 'render_prompts'
        C:\Users\userid\AppData\Local\clink\flexprompt.lua:1380: in function <C:\Users\userid\AppData\Local\clink\flexprompt.lua:1379>
        {prompt.lua}: in function <{prompt.lua}:71>
        [C]: in function 'xpcall'
        {prompt.lua}: in function <{prompt.lua}:53>
        (...tail calls...)

Interesting.

I understand the intent behind "it would be nice to catch any exception in the prompt code".

What do you propose it should do in response to an exception that the Lua code didn't expect?

It would cause a worse problem if it silently and completely disabled the prompt code, and fell back to whatever %PROMPT% says.

Clink catches any exceptions, which is why it's able to display an informative error message (which makes identifying and fixing the issue very easy).

In a few days, when I get a chance, I'll make the git prompt filter more resilient to missing data. About all it can do in that case, though, is display "error" in the git error color.

I'll also consider whether clink-flex-prompt can catch exceptions in prompt modules and do some kind of halfway reasonable thing in response. Maybe it can define a general error color, and maybe if a prompt module hits an exception then clink-flex-prompt could write the full error info message to the log file, and insert a prompt segment that says "error" using the general error color. And maybe it can add a line above the prompt saying to look in the clink log file for error details.

I had not really thought about alternatives before. But your last paragraph sounds quite good. A line above the prompt telling to look into foo.log for all details about the error seems a good compromise between alerting and still being able to use the terminal. I've experienced a similar solution in other applications for showing internal errors in UI components with restricted space, and that was okay to me.

The only thing the git prompt filter can do when there's no HEAD is assume that it's not a git repo, and simply do nothing at all. I've updated it accordingly.

I considered whether to add some kind of fancy reporting for unhandled exceptions above the prompt text. But catching unhandled exceptions and trying to continue gracefully can lead to even worse failures such as infinite loops. The current behavior for unhandled exceptions is much safer and more informative.