kmonad / kmonad

An advanced keyboard manager
MIT License
3.9k stars 318 forks source link

Config error reporting #57

Open thoelze1 opened 4 years ago

thoelze1 commented 4 years ago

When the number of seconds is omitted from the definition of any of the variations of tap-hold, the error reporting is unclear. For example, with the following config:

...
(defalias
  q (tap-hold a lsft)
)
...

The following error is reported:

kmonad: Parse error at #:##:
  |
# |   q (tap-hold a lsft)
  |               ^
unexpected 'a'
expecting button

I would expect this to say "expecting int" or something along those lines. I think I've noticed some other issues with the error reporting but I just wanted to start a thread for this issue while I'm thinking of it.

david-janssen commented 4 years ago

Yep, this is very much an issue. Thank you for creating one on Github, now it doesn't have to live only in my head.

The issue is very simple, config-file reading happens in 2 steps:

  1. We read the raw text into abstract configuration objects. (Parser.hs)
  2. We try to construct a meaningful config from the configuration objects. (Joiner.hs)

The second step already has relatively clear errors that make sense. The first part currently just reports the raw errors thrown by the parser. In your concrete example, it reads 'tap-hold', it knows that now it has to read some kind of number, it encounters an 'a', which is not a number, and reports that issue.

Basically, we have to go through the Parser.hs code and add better error reporting.

For example, for this particular issue, I think we can change the lexeme numP (line 239 a.t.m.) into a new Parser, like timeP, and use the <?> operator to specify correct error reporting.

The reason is currently reports button is because that is the first <?> it encounters (at the end of buttonP, basically saying, "I was expecting you to give me a valid button, I encountered a weird a, you didn't give me a button".

manna-harbour commented 3 years ago

In addition to more informative error messages in general, it would be nice if all error messages included the filename, line and column, and were in a standard format, to enable jumping directly to the source of the error when checking for syntax errors with kmonad -d in your editor (e.g. emacs M-x compile).