Careful what you name things
On Friday I decided to create a new class called Failure. A Failure is stored anytime an unexpected exception is raised in our application. There are various subclasses to indicate many specific types of failures such as FrontendFailure and BackendFailure, each of which has different behavior. For example, FrontendFailure might send e-mail after_save. Other failure classes represent expected but unhandlable errors like "your template code is wrong". In those cases we can e-mail the user. We could even look through the failures to see if the user's problem has been fixed yet.
The failures table. (data is a serialized OpenStruct so subclasses can store anything they like)
create_table :failures do |t| t.column :type, :string t.column :exception_class, :string t.column :exception_message, :string t.column :backtrace, :text t.column :message, :string t.column :data, :text t.column :status, :integer t.column :created_at, :datetime t.column :updated_at, :datetime end
Sample usage.
begin do_something_big_and_complicated rescue ComplicatedError => e ComplicatedFailure.occurred e, "it happened again" end
Ok, so this works great. No problems. The problem was more subtle. Really subtle.
As I worked on this bit of code and started using it to debug various features, I started getting depressed. Not slit-your-wrists depressed but definitely bummed. Having just read Malcolm Gladwell's excellent Blink I can only say it was from constantly reading, typing, and thinking about "failure" over the course of a few hours.
This isn’t Typo
Thought I should mention that this site isn't using Typo anymore. It had been running on a very old, and heavily customized version which made it extremely hard to upgrade. I started looking at converting to new version with themes and felt like it was overkill. What was once little Typo has really grown into a non-trivial app.
Instead, I whipped up something really simple called Post. A short list of features..
All in 431 lines of code and 423 lines of test. Remember when this stuff was hard?