Saturday, September 03, 2022

Why YAML, Why?

 Last night I finally joined the ranks of those who despise YAML. I've always known (and known of) admins who loathe YAML. They rail against it every time they have to use it, or any time it is even mentioned. Primarily, they complain about it being white space sensitive.

  In the past, I considered this an extreme reaction. An overreaction to a minor annoyance. I'd not encountered any problems in using YAML so far, even when making the same edits they complained bitterly about. I considered the indentation fairly logical, and figured that if you treated YAML a bit like a wild animal, by giving it some respect and moving slowly, that it wasn't very likely to bite you and everything would be fine. For a long time, it was. Until it wasn't.

  I should preface that my bad experience with YAML did occur at almost 2am, so I wasn't functioning at peak capacity by any means. I was trying to implement Authelia for my self-hosted sites and it uses YAML for its config and its on disk user database both. I finished configuring it and launched it for the first time, then tried visiting my site, and got a 500 error. 

  Several rounds of troubleshooting later I found that the container was failing due to errors reading the config file. I found the line number where it began complaining about not finding expected keys and took a look, but couldn't see anything wrong. After many attempts, I ended up going back to the sample config file I had copied as the base for my file, and copied several lines to either side of the offending line. I then removed these same visually identical lines from my config, and pasted those from the sample config back in. Visually, nothing had changed, but the logs no longer complained about errors in the configuration.

  Instead, they complained that the display name of my one user couldn't be an empty value. It wasn't empty. I tried several variations, before finally tracking down a sample file, commenting out my entry, pasting in the sample, and then modifying it with my user's details. And it worked. Annoyingly.

  My best guess is that there was whitespace, either tabs vs spaces, at the ends of the lines, or on seemingly blank lines that was the source of the problem. Visually, there were no differences between the working and the non-working code. Indentation was the same. And of course, the error messages are very unhelpful. The problem wasn't that the value was empty, but that something else was causing the parsing to be incorrect.

  So, freshly burned by this experience, I have reluctantly converted to the side of those who consider YAML a terrible format for configuration files. There are much more forgiving options out there that don't require dark magic or blind copy pasting to get working when nothing is visually wrong with the data. 

  You won't convince me that whitespace is a problem in Python though. Not yet at least.

No comments:

Post a Comment