10 March 2021

Buffalo New” and Missing Templates

I was working on a Buffalo app over the weekend, and I made a mistake which manifested in an interesting way. The Buffalo framework is a lot like Ruby on Rails: it’s a rapid development tool for web applications backed by a database, but it uses Go instead of Ruby. A lot of this development speed comes from using generators, of which Buffalo has two different types: one for creating new applications, which is executed when running buffalo new, and one for adding stuff to an existing application, which is executed when running buffalo generate <thing>. The trouble is I can never quite remember which one is which.

I wanted to create a new resource, which is effectively a new model to store in the database along with some screens to modify it. However, I accidentally ran buffalo new resource, instead of buffalo generate resource. I saw that Buffalo was starting to generate a new project, completely within my existing project. I quickly pressed Ctrl+C, hoping to stop it before it began destroying work. Once it stopped, I took a brief look to see if any files were changed or removed. There was a new resource” directory, but thinking that this was where working files went, I didn’t think much of it. Thinking that I caught it in time, I continue working on the project.

Then I started seeing weird things happen, like Buffalo being unable to find JS or CSS files, or being unable to find templates to generate HTML pages. This only happened intermittently: after a few restarts, the application started working again. I knew that it somehow related to the mistake I made, but going through my Git history, I didn’t see any files deleted or modified, so I was unsure as to what the problem actually was.

I finished the feature I was working on, and deployed it to my server. It started up properly and I did some quick testing before finding a few things I wanted to fix. I made the fix and deployed it again. I tried to go to the home screen, and I saw a system error. I tried again: system error. From the logs I looked like the same problem I saw in development: missing JS, CSS and template files. I started doing the things I did in development, like restarting or redeploying the app. I even started doing things like upgrading the version of libraries. No good. I was constantly seeing system error.

This morning, I decided to take a good look through the Git commits to see what actually changed. It was only then that I realised that new resource” directory was not part of the original app, but was instead a completely new Buffalo app, complete with templates, JS and CSS files. It turns out that running buffalo new didn’t modify any of my existing files, but it did go through with creating a brand new app.

I’ve removed the resource” directory completely and redeployed the app. The system errors disappeared and I saw the app run again.

So if there is anyone else using Buffalo that is experiencing intermittent issues with the app being unable to find JS, CSS or templates, check to see if you’ve accidentally run buffalo new instead of buffalo generate.

Previous post
On Go Libraries Authors Coding to Interfaces One convention of the Java programming world that I really like is the encouragement of writing code to interfaces instead of concrete types. When
Next post
GitHub Feature Request: Prevent PR Merges Based On Code Comment Patterns Something that would be nice to see in GitHub and Bitbucket is the ability to prevent merging of a pull request if a comment containing a particular