Qball's Weblog
Rofi 1.4.0: Sneak Preview (6): Errors
In this blog post we will go into debugging a new theme in the new format. Given there are, a lot, more options now this will be a bit harder. But as always there are two sides. The old, xresources format, parser on the other hand did not have a lot of error handling. Neither did the code using the values. Hopefully now what we a custom parser we can improve on this.
We can divide the errors into two different types. The first are syntax errors, text in the theme the parser does not understand. The second are logical errors, while the syntax might be correct, the set values have no meaningful meaning.
Syntax errors
Syntax errors are often the easiest to debug, they stop the parser parsing the file and will throw an error.
Syntax errors are errors like missing ; after a property, invalid text in the
theme and more.
The parser will tell you what it found and what it expected to find. In addition it will show where the error occurred.
To give an example:
Monkey {
}
We know this is not a valid entry, the parser expect # specifying a theme
element, a * indicating a global settings block or a configuration block.
This is also what the parser will tell you:
Try it yourself:
rofi -show run -theme-str 'Monkey { }'
See:

Parsing string: 'Monkey {}'
Failed to parse theme:
Error while parsing theme: Monkey {}
Parser error: syntax error, unexpected error from file parser, expecting end of
file or "Element section ('# {name} { ... }')" or "Default settings
section ( '* { ... }')" or Configuration block
Location: line 1 column 1 to line 1 column 2
It will also indicate on what line and what column the error is (tabs are considered one column). If the error is in a file, it will also show the filename.
If the theme is not fully finished, you get an error like:
Try it yourself:
rofi -show run -theme-str '#bami { nass }'

Here you see that it sees an unexpected }, this is correct, because it would
expect the separator ‘:’.
Note: Imports and comments are handled in the lexer, lexical analyzer. This is why you will not see this as one of the
expectedoptions.
If you specify an invalid @import "file". For example a file that does not
exists, this will be reported.

Failed to open theme: /home/qball/Testing/bami
Error: No such file or directory
If an error occurs parsing while parsing the theme, but it happens in an imported file, the error shows as follow:

You can see it shows the theme file it parsed and the file where the actual error occurred.
Logical errors
While syntax errors are often clear, logical errors can be harder to find. For example the following setting:
#window {
border: true;
}
There is no syntax error in this. But border should be a string, not a boolean.
Currently the parser does not know this and won’t throw an error.
Try it yourself:
rofi -show run -theme-str `#window {border: true;}`
As you can see no error, but the borders in rofi might be missing.
When looking up the border property rofi looks up both border and type
of property. The parsed entry is of type boolean and therefor ignored.
What you can do is enable the debug output on the theme engine.
G_MESSAGES_DEBUG=Theme rofi -show run `#window {border: true;}`
This will spit out a lot of messages like:
(process:6611): Theme-DEBUG: Theme entry: #window.box property fullscreen unset.
(process:6611): Theme-DEBUG: Theme entry: #window.box property padding unset.
(process:6611): Theme-DEBUG: Found property: 'border' on 'box', but type Boolean does not match expected type Padding.
From this we can see what properties where queried, but no setting was found in
the theme. Here we see that the border setting was ignore because the type did
not match.
Giving a hint that the property was not correct.
See the specification for more details on how properties are parsed.
comments powered by Disqus