Well for a variety of reasons, all of our ultra cool agents, we have a nearly 6,000 line single YAML file that is our base configuration. So it is nearly impossible to figure out what is wrong because it is not incorrect syntax, but the tool (TNE Compass if you must know) is very picky about semantics such as:
- If there is a blank field like “description:”, this particular app will fail the entrie YAML file silently
- If there is a duplicate in keys like a “slug:” field then the entire thing fails
The best way to debug: neovim folds and bisecting
Well there are lots of workflows to debug this, but with such a big file, a few tricks work well:
- Bisecting. That is the age old trick of finding a problem. Split the file in half and reload. If it is still broken then divide it in half and try again. It’s amazing how few bisections you need to identify a problem (ok, it’s ln(n) lines, but who is counting 🙂
- NeoVim Undo. One trick here is that the latest versions of neovim and most modern editors have unlimited undo, so you can just delete have the file and then if it works, you just hit undo and get the whole file back.
- Keeping track of this in a separate little notepad/calculator helps alot
- LazyVim Foldings. With YAML files, it’s hard to navigate through them all, but if you use LazyVim, you can use folds. This is a neat command set, so that
zM
will “fold” that is hierarchically hide each layer, then you do azo
which opens the layers so you can see the top level of the YAML. - YAML – LazyVim. Make sure your YAML is valid before you do this with YAML linting
When you combine all this, you just zM
everything and then you can bisect by YAML components and fix it in no time.
Leave a Reply
Only people in my network can comment.