Fixes to poet

Nov 17, 2013

So, I moved this website over to poet recently for the sole purpose of making it easier for me to publish posts right from Emacs (by writing the posts in a simple markdown file in a local git repo, and the pushing the changes over to my server and staging them). However, right off the bat I ran into a couple of issues. Poet comes with a feature that allows it to monitor your posts directory for any changes, and then it reloads all posts the moment it detects any new files/modifications to existing files/deletion of files. However, this wasn’t working in practice, and I was being forced to ssh to my server and manually reload the running instance of poet, which kind of defeated the whole point of moving to poet in the first place. So, having found some time on my hands over the weekend, I sat down to figure out what was going wrong, and to see if I could fix things somehow. Turns out that there were three problems; one was in my posts, and the other two were in poet itself. Funnily enough, all three of them affected one another.

  1. One of my posts had an invalid title (it had unescaped quotes in it). As a result of this, the JSON-parsing logic in Poet was messing up.
  2. The reason this logic was messing up, is because there was a regular expression in there that was looking for global matches, despite the code that used the regular expression only dealing with the first match it found. This global match flag was barfing on my invalid JSON, causing the next post’s parsing to fail altogether, which is why it was so much harder to catch
  3. Finally, the next post’s parsing was throwing an error, which was causing the whole deferred chain to fail, hence resulting in the reload functionality never actually getting invoked

All things considered, it was a fun series of bugs to track down, and I’ve opened two pull requests on the original repo, which should hopefully get merged sooner or later. In the meantime, I’m running my instance of poet off of my own forks (github repo URLs in package.json FTW!) and I did get to finally sit down and understand what javascript promises are, so all-in-all it was a good day.