In a REST API I was writing, I wanted certain unlikely failures effecting customers to get logged to BugSnag as warnings so we would know if there was a pattern of failures, even if customers didn’t follow the instructions on the page to let us know.
From what I could tell reading the docs, BugSnag wanted me to pass it an error (exception) of some kind but these failures weren’t raising exceptions, they were just returning appropriate 4xx HTTP error codes.
There’s probably a better way of doing it but my eventual solution involved creating, but not raising, an error:
e = StandardError.new(‘Verified successfully but couldn’t fetch any records’)
Bugsnag.notify(e)
By the way, I would normally use a more descriptive variable name but I think this is one of those rare exceptions (pun not intended) where the meaning is so obvious and the variable is so short lived that it’s acceptable. A bit like using i
and j
as variables in a loop.
I tested this code from the production console to make sure it worked and that notifications came through to our internal chat app. What I noticed is that, perhaps because I didn’t raise
the errors, the Bugsnags didn’t include helpful backtrace information like file names, line numbers or method names. The docs revealed a set_backtrace
method and StackOverflow pointed me in the direction of [caller](https://ruby-doc.org/core-2.5.3/Kernel.html)
.
Of course I found myself using this same code 4 times in the same file, an obvious candidate to split into a method. Of those 4 times, they were split evenly between warnings and errors so the method needed to allow for that. I also wanted to be able to add a tab to Bugsnag with arbitrary information. Skipping to the finished product, the end result was:
def notify_via_bugsnag(message:, severity: 'warning', aditional_info: {})
e = RuntimeError.new message
e.set_backtrace caller(2)
Bugsnag.notify(e) do |report|
report.severity = severity
report.add_tab(:appname_API, additional_info) if additional_info.present?
end
end
The main thing to note is the addition of (2)
to caller
. Because I’m setting the backtrace from within a called method I want it to start one frame higher in the stack.
I then consumed this method in the controller with code like this:
notify_via_bugsnag(message: 'Requestor was verified but student data wasn\'t saved',
severity: 'error',
additional_info: {
student_id: params[:id],
})
head :unprocessable_entity
📚 I’m reading Seeing What Others Don’t by Gary Klein and came across this great quote:
The greatest obstacle to knowledge is not ignorance; it is the illusion of knowledge. — Daniel Boorstin
While I’m on the book theme, we listened to “Here Be Monsters” by Alan Snow (read by Bill Wallis) in the car as a family.
I’m a huge fan of borrowing audio books and ebooks from our local library on my phone using Bolinda BorrowBox. So convenient! 📚
These holidays I also re-read “Only Time Will Tell” by Jeffrey Archer (2013). It was a great read and I’m looking forward to reading the rest of the series (currently on reserve). 📚
Aforementioned (old but pretty good) book was “Inside Steve’s Brain (Expanded Edition)” by Leander Kahney (2009).
I don’t think it needed the “Lessons from Steve” at the end of each chapter but other than that I enjoyed it. It was well researched and well written 📚
For a long time I have liked the idea of being self-employed. I’m sure there are many romantic (and perhaps even foolhardy) notions that play into this desire but ultimately I think I like the simplicity of it; the fact that the authority, AND the responsibility, stop with me. I have contemplated it several times in the past but I am (trepidatiously) pleased to share that today marks 10 weeks since I left full time employment in order to focus on my own endeavours. In this post I wanted to share some of the thinking that went into my wife and I making this decision.
There are two schools of thought on how best to transition from salaried work to self-employment. The most common advice I hear is to stay at your day job but to build something up on the side. The advice goes that you will know it’s time to quit your day job when your side business is making enough money to sustain you financially or when demand for your side business regularly exceeds the time you are able to dedicate to it. On episode 8 of Cortex (Internet) famous podcaster and YouTuber CGP Grey talks with fellow (Internet) famous podcaster Myke Hurley about how they both took this approach.
The main problem I have with this approach is that your day job will inevitably suffer. In the Cortex episode I linked to above, CGP Grey talks about getting up early and dedicating the best of his time and energy to his side business rather than wasting it (my words) on his day job while Myke Hurley would frequently work on his side business until the wee hours of the morning and be exhausted the next day at work. Personally, I don’t feel comfortable with that approach. Withholding that which I’ve (implicitly) committed to give my employer feels a bit like stealing and doesn’t gel with my beliefs about doing everything for God’s glory.
The other approach to self-employment I hear people suggest is the sink or swim approach. The idea is that if there’s a market for your skills and you have 3-6 months of living expenses saved up then just quit your job and give it a go. You’ll either sink, and have to go back to a regular job like the one you had before, or you’ll figure out how to swim, and you’ll have successfully transitioned to self-employment.
I have two problems with this approach. The first is how it impacts other people. It seems like this could be a reckless and irresponsible way of trying self-employment, particularly with a family to support and a mortgage to pay. My other problem with this approach is that I think it requires less commitment. Quitting a job may give the appearance of being committed but it’s a once off thing and doesn’t demonstrate an ability to show up day in and day out, even when the excitement has worn off.
In the end I went with the second approach. I don’t think it’s the right approach for most people, and for some people it’s decidedly the wrong approach, but it’s what I did. So was it reckless? Does it demonstrate a lack of commitment on my part that I didn’t (couldn’t?) build up a side business while I was still employed?
To answer the first question there is definitely some risk involved but I don’t think my wife and I were reckless. We are very blessed to live in Australia, a country with universal health care and reasonably robust social security benefits. We are also blessed to have two sets of parents between us (and four sets of grandparents!) who would willingly do whatever they could to help us if things became financially dire.
Not that I expect things to become dire. Before I quit my job I developed an “Expenses Runway” calculator. Based on our current position, and even if I don’t earn another cent, we have about 26 weeks (6 months) before we would start to fall behind on our budgeted living expenses (assuming no “extra-budgetal” surprises). I update our financial position every Friday arvo and if we get down to 12 weeks of runway I plan to start looking for a good job, if we get down to 8 weeks I’ll start looking for any job and if we get down to 4 weeks I’ll start mowing lawns, flipping burgers and washing windscreens.
The answer to the second question is less clear cut. I am a little worried that my inability to build up a side business while I was still employed does in fact demonstrate a lack of commitment. The fact that I haven’t even finished developing my business plan after 10 weeks also concerns me.
On the other hand, I have been making good progress putting things in place. I have also learned lots about business, tax and accounting, I’ve started exploring a number of opportunities and I am slowly but surely increasing my productivity.
It’s far too early to call this a success but I feel like I am in a better position now, spiritually, professionally and personally, than I was ten weeks ago. If I can continue that trend then I’m sure the finances will follow soon enough.