22
loading...
This website collects cookies to deliver better user experience
This is Day 11 of the #100DaysOfPython challenge.
PrettyErrors
library to output more readable errors in Python.PyInquirer
basics in a previous blog post.PyInquirer
hello-python-fire
repo, the follow will work in any repo initialized with pipenv
.# Add PrettyErrors
$ pipenv install pretty_errors
cli.py
to raise a very contrived exception:#!/usr/bin/env python
import fire
from PyInquirer import prompt
class IngestionStage(object):
def run(self):
raise Exception("Contrived example")
return 'Ingesting! Nom nom nom...'
python cli.py ingestion run
we will see the following error:$ python cli.py ingestion run
Traceback (most recent call last):
File "/Users/dennisokeeffe/code/blog-projects/hello-fire/cli.py", line 66, in <module>
fire.Fire(Pipeline)
File "/Users/dennisokeeffe/code/blog-projects/hello-fire/.venv/lib/python3.9/site-packages/fire/core.py", line 141, in Fire
component_trace = _Fire(component, args, parsed_flag_args, context, name)
File "/Users/dennisokeeffe/code/blog-projects/hello-fire/.venv/lib/python3.9/site-packages/fire/core.py", line 466, in _Fire
component, remaining_args = _CallAndUpdateTrace(
File "/Users/dennisokeeffe/code/blog-projects/hello-fire/.venv/lib/python3.9/site-packages/fire/core.py", line 681, in _CallAndUpdateTrace
component = fn(*varargs, **kwargs)
File "/Users/dennisokeeffe/code/blog-projects/hello-fire/cli.py", line 8, in run
raise Exception("Contrived example")
Exception: Contrived example
#!/usr/bin/env python
import fire
from PyInquirer import prompt
import pretty_errors
class IngestionStage(object):
def run(self):
raise Exception("Contrived example")
return 'Ingesting! Nom nom nom...'
python cli.py ingestion run
we will see the following error:$ python cli.py ingestion run
--------------------------------------------------------------------------------------------------------------
cli.py 67 <module>
fire.Fire(Pipeline)
core.py 141 Fire
component_trace = _Fire(component, args, parsed_flag_args, context, name)
core.py 466 _Fire
component, remaining_args = _CallAndUpdateTrace(
core.py 681 _CallAndUpdateTrace
component = fn(*varargs, **kwargs)
cli.py 9 run
raise Exception("Contrived example")
Exception:
Contrived example
PrettyErrors
to make our error debugging experience much more pleasant.basilsamuellade