Now Featuring! - Lab 3

 Once again, I was tasked to enhancing the Link Checker that I started out the semester with. As a change, however, pull requests were off-limits! This time around, only the handy-dandy feature known as git merge was available to use.

Along with a new method to commit my work, I also had to change my habits by implementing two features on separate branches, and committing them as two independent additions to the main branch. The two features I chose to add to this project was a filter for links, as well as introducing exit codes for development purposes.

While I was able to try and do both of these features at the same time, I took more of a methodical approach and put all of my focus on them individually.

To start, I chose to work on the exit codes. This task, once I was able to figure out how Python handled errors and outputting exit status, was actually quite easy. I already had a handful of try-except blocks in the code (for when links timed out), so that was a good starting point. From there, I tried to break my program any way that I could think of (from passing text files where I expected a web address, to intentionally inputting a link that didn't exist). I took the error codes that the system threw back at me, and set up the additional excepts. These errors ranged from OSError (for when I gave the program a web address when I was expecting to parse through a file) to ConnectionError (for when a broken link had timed out while I was trying to connect to it). Within all of these excepts, I followed a pretty standard template: output a message to the user, set a unique error code number, and then return that number so the program could later use it during termination. Speaking of which, the program termination I chose to utilize was sys.exit() which, as explained to me by Mohammed Ahmed, was the ideal way to cleanly kill the process.

With that feature complete, I shifted my focus to add the filtering of links that I needed for specific queries. With some research on Click and its Feature Switches, I knew I had found exactly what I needed. Based on which option the user specified, I would change the value of a single flag variable, which I would then pass to my link_checker() function. Since I already had checks for each link status code implemented there, I only had to add an additional check on the corresponding flag that was needed, and the feature was complete! Definitely was the easier of the two features.

I've included a sample of my code below (the link_checker() function). Within it, there is an example of both features; the exit codes set up at the bottom within the except, and the link filtering through out the function as it checks the link status codes.

 And that's it! All I had left to do was merge each issue. I quickly merged up my first feature, and everything was so easy! I was confident I would be done in no time. So I then proceeded to merge my second issue... and then the fun began. Even though the two features were very independent of each other, they both overlapped in changing enough code that the second merge was far from simple and clean. Not quite remembering what to do from there, I went back to watch the video from earlier that week, hoping for David Humphrey to save the day! While I was able to make some more detailed notes on what may help me in the future, in the end, I had to do some manual labor to finish the merging process.

After adding a few lines here, typing in a few missing variable there, and fixing up some formatting from the added 'if' statements, I was ready to do final tests on the code. Luckily, I already had debug scripts made up for each of my case scenarios, so I was able to click a button and walk away for a bit while the program did its thing. Luckily for my sanity, everything came out as expected, and I was able to make a quick push to master to set it in stone, and close the 2 issues!

All in all, this entire experience was fairly pain-free for me, and while I learned that not everything can come as easy as clicking a button, I discovered that I can focus in on a specific task and know how to only code for what I'm trying to solve, even if there's another feature in the back of my mind ready to be made.

Comments