My CLI caught a COLD
Today, I will take you through the crazy journey of how my CLI caught a “cold”, how I cured it, and how I ended up crating better error handling because of the whole adventure.
How dose a CLI catch a cold?
So, one day (yesterday), I was using SpellCLI and than suddenly a bunch of treads started to panic, for seemingly no reason! Than, I ran the program again, and it worked perfectly fine.
After a few more tests, the CLI seemed to very in the number and how often these threads panicked. It reminded me of how I am when I have a cold (working in varying efficiencies), so I thought to label the CLI as having a cold (I know it’s not the correct way of labeling a program with this status, but I though it would be funny) .
DON’T PANIC
And just like that I was off to debugging! First, I started with adding debug info like adding names to treads and printing a bunch of information.
After a little bit, I found out that the treads that are panicking are the ones that retrieve definition data from the internet. Specifically, the treads are not getting JSON data but “error code: 502”
Handling the errors
Turns out that error code: 502 means that a bad gateway has interfered with everything, and the best solution is to… try again later. I don’t know why this is just now showing up. If you know or have a guess, feel free to comment!
What this all means is that I had to handle internet errors now. So, I changed the get_word_defs function to return a Result and made the treads handle the result: if a tread got the error 502, it would try again up to 3 times, and it would display any other error to the user! It might not be the most perfect or cleanest fix but it works for the most part!
And with that I am done! Right?
I patched up the CLI and published the new version on crates.io! but, I sometimes get the error 1015 (meaning I set too many requests) and there are a few other things that could be worked on… For now, I’m going to go back to the bevel gears.
Comments 0
No comments yet. Be the first!
Sign in to join the conversation.