jesseduffield / jesseduffield/lazygit
Incorrect custom command configuration is handled poorly
- Dominant language
- Go
- Stars
- 82.4k
- Forks
- 3k
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 19
Description
**Describe the bug**
I was trying to set up a custom command for the first time.
```yml
customCommands:
- key: ''
context: 'localBranches'
command: 'git merge master'
```
Putting that in my config and launching lazygit on Windows causes it to just immediately terminate with no error message and a strange artifact at the edge of the window.

Only later did I learn that ctrl-m was not supported: [docs/keybindings/Custom_Keybindings.md](https://github.com/jesseduffield/lazygit/blob/master/docs/keybindings/Custom_Keybindings.md)
https://github.com/jesseduffield/lazygit/blob/0fd7b9baa41d03c1ce04321c41e0fbd455f08c82/pkg/gui/keybindings/keybindings.go#L110
log.Fatal while the TUI has already started appears to cause this issue. I tried different shells and terminals on Windows to the same result. On WSL, it's better but multiline log.Fatal's still do not render quite correctly

(This log.Fatal happens when providing an invalid custom command context)
I think the ideal behavior would be for the custom command key/context validation to happen in https://github.com/jesseduffield/lazygit/blob/853a04dfd070271c8144fe66c2a5a8e3dadf0318/pkg/config/app_config.go#L207
Custom command misconfigurations would then behave consistently with how other user config errors are (gracefully) handled:
1. If a config misconfiguration happens on startup, then lazygit cleanly prints the error and exits before starting the TUI.
2. If a config misconfiguration happens during user config reload, an error popup will be shown and the old valid config will still be used instead of immediately crashing.
3. If a config misconfiguration happens during repository switch, an error popup will be shown and the switch will be prevented instead of immediately crashing.
Actually making that fix is a bit of a refactor though...
Also, I noticed there are 3 disagreeing sources for what is a valid context value.
1. The docs: https://github.com/jesseduffield/lazygit/blob/master/docs/Custom_Command_Keybindings.md#contexts
2. What is actually allowed: https://github.com/jesseduffield/lazygit/blob/853a04dfd070271c8144fe66c2a5a8e3dadf0318/pkg/gui/services/custom_commands/keybinding_creator.go#L65 (basically any context key, for example `context: 'statusSpacer1'` is accepted...)
3. The context keys listed in the log fatal error message: https://github.com/jesseduffield/lazygit/blob/853a04dfd070271c8144fe66c2a5a8e3dadf0318/pkg/gui/services/custom_commands/keybinding_creator.go#L87 Almost the same as 2 but missing some of the more recently added context keys.
**To Reproduce**
Steps to reproduce the behavior:
Add
```yml
customCommands:
- key: ''
context: 'localBranches'
command: 'git merge master'
```
or
```yml
customCommands:
- key: ''
context: 'localBranches2'
command: 'git merge master'
```
to your config and then launch lazygit
**Expected behavior**
See above
**Screenshots**
If applicable, add screenshots to help explain your problem.
**Version info:**
master branch
**Additional context**
Add any other context about the problem here.
**Note:** please try updating to the latest version or [manually building](https://github.com/jesseduffield/lazygit/#manual) the latest `master` to see if the issue still occurs.
Contributor guide
Assessment
This issue has not been assessed yet.