Addressing a bug
Some bugs are more severe than others. In a best-case scenario, your bug is seldom encountered, or when it does occur it’s not a big deal. In a worst-case scenario, your bug loses you money. Let’s focus on a case where the bug loses you money in a scenario where you’re running an e-commerce site.
Hopefully, this code has never been shipped in production, but it’s a good example of a bug that could be catastrophic for an e-commerce site:
def process_cart():
# get cart from database
cart = get_cart()
card = cart.get_card()
process_payment(card, cart)
ship_order(cart)
The problem you might have is that ship_order
is called even if process_payment
fails, which means you ship orders without getting paid, losing you money.
Looking at this code, you might not have a problem if process_payment
throws an error and you don’t even get to ship_order
.
What if it doesn’t and, instead, returns a numerical...