pwaller/pyfiglet

better error handling of "FontNotFound"

mkinney opened this issue · 2 comments

Currently, when the font is not found, it spews a large traceback:

% pyfiglet -f "ANSI Regular" "Hello"
Traceback (most recent call last):
  File "/nix/code/python_large_font/venv/bin/pyfiglet", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/nix/code/python_large_font/venv/lib/python3.11/site-packages/pyfiglet/__init__.py", line 927, in main
    f = Figlet(
        ^^^^^^^
  File "/nix/code/python_large_font/venv/lib/python3.11/site-packages/pyfiglet/__init__.py", line 794, in __init__
    self.setFont()
  File "/nix/code/python_large_font/venv/lib/python3.11/site-packages/pyfiglet/__init__.py", line 801, in setFont
    self.Font = FigletFont(font=self.font)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/code/python_large_font/venv/lib/python3.11/site-packages/pyfiglet/__init__.py", line 126, in __init__
    self.data = self.preloadFont(font)
                ^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/code/python_large_font/venv/lib/python3.11/site-packages/pyfiglet/__init__.py", line 147, in preloadFont
    raise FontNotFound(font)
pyfiglet.FontNotFound: ANSI Regular

Perhaps it could be improved to simply say something like "Error: pyfiglet.FontNotFound: ANSI Regular".

Seems like a relatively simple piece of excption handling for anyone who wants to start contributing to this package. Might be worth flagging as such @pwaller.

A patch would be welcome, indeed.