Skip to content

Commit ef6c6ea

Browse files
ddemidovWasabiFan
authored andcommitted
Provide meaningful error on attempt to load non-existent font (#261)
Fixes #260
1 parent 8f33b80 commit ef6c6ea

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

ev3dev/fonts/__init__.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ def load(name):
1919
`PIL.ImageFont <http://pillow.readthedocs.io/en/latest/reference/ImageFont.html>`_
2020
class.
2121
"""
22-
pil_file = pkg_resources.resource_filename('ev3dev.fonts', '{}.pil'.format(name))
23-
pbm_file = pkg_resources.resource_filename('ev3dev.fonts', '{}.pbm'.format(name))
24-
return ImageFont.load(pil_file)
22+
try:
23+
pil_file = pkg_resources.resource_filename('ev3dev.fonts', '{}.pil'.format(name))
24+
pbm_file = pkg_resources.resource_filename('ev3dev.fonts', '{}.pbm'.format(name))
25+
return ImageFont.load(pil_file)
26+
except FileNotFoundError:
27+
raise Exception('Failed to load font "{}". '.format(name) +
28+
'Check ev3dev.fonts.available() for the list of available fonts')

0 commit comments

Comments
 (0)