Dennis O'Keeffe
2 min readSep 1, 2021
Heading image

This is Day 11 of the #100DaysOfPython challenge.

This post will use the PrettyErrors library to output more readable errors in Python.

It will build off the work done on learning Python Fire and PyInquirer basics in a previous blog post.

Prerequisites

  1. Familiarity with Pipenv. See here for my post on Pipenv.
  2. Familiarity with Python Fire
  3. (optional) Familiarity with PyInquirer

Getting started

While I will be using my hello-python-fire repo, the follow will work in any repo initialized with pipenv.

We are now able to begin throwing some example errors.

Demonstrating the error

Python Fire requires valid input for method arguments for how it operates.

We will simply update the top of the code for cli.py to raise a very contrived exception:

Now if we run python cli.py ingestion run we will see the following error:

Prettifying the error

To see Pretty Errors in action, all we need to do is import the package:

Now if we run python cli.py ingestion run we will see the following error:

A much nicer and easier-to-debug output error.

Summary

Today’s post demonstrated how to use the PrettyErrors to make our error debugging experience much more pleasant.

Resources and further reading

  1. The ABCs of Pipenv
  2. PrettyErrors
  3. Pipenv
  4. CLI Prompts In Python

Photo credit: basilsamuellade

Originally posted on my blog. To see new posts without delay, read the posts there and subscribe to my newsletter.

I write content for AWS, Kubernetes, Python, JavaScript and more. To view all the latest content, be sure to visit my blog and subscribe to my newsletter. Follow me on Twitter.

Dennis O'Keeffe
Dennis O'Keeffe

No responses yet