Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle exception for missing fonts -- causes crash #60

Open
txoof opened this issue Feb 2, 2022 · 0 comments
Open

handle exception for missing fonts -- causes crash #60

txoof opened this issue Feb 2, 2022 · 0 comments

Comments

@txoof
Copy link
Owner

txoof commented Feb 2, 2022

crash on startup when fonts are missing can likely be remedied by wrapping the plugin loader in a try/except for OSError.

05:24:52 686322451:build_plugin_list:38:INFO - [[ Plugin: Crypto Bitcoin v EUR ]]
05:24:52 Layout:_add_defaults:142:DEBUG - [[----checking default values for layout----]
05:24:52 Layout:_add_defaults:144:DEBUG - section: [---------update_time----------]
05:24:52 Layout:_add_defaults:144:DEBUG - section: [----------coin_file-----------]
05:24:52 Layout:_add_defaults:144:DEBUG - section: [---------price_string---------]
05:24:52 Layout:_add_defaults:144:DEBUG - section: [------change_vol_string-------]
05:24:52 Layout:_add_defaults:144:DEBUG - section: [----------sparkline-----------]
05:24:52 Layout:_add_defaults:144:DEBUG - section: [-----------qr_code------------]
05:24:52 Layout:_add_defaults:144:DEBUG - section: [-----------rss_feed-----------]
05:24:52 Layout:_calculate_layout:190:DEBUG - [[....calculating layouts....]]
05:24:52 Layout:_calculate_layout:192:INFO - section: [.........update_time..........]
05:24:52 Layout:_calculate_layout:196:DEBUG - resolution: [1200, 825]
05:24:52 Layout:_calculate_layout:197:DEBUG - width: 1, height: 0.1
05:24:52 Layout:_scale_font:240:DEBUG - scaling font size
---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
Input In [23], in <module>
      7         sys.argv.extend(r)
      8 #         sys.argv = [sys.argv[0]]
      9 #         sys.argv.extend(sys.argv[2:])
---> 10     exit_code = main()
     11     sys.exit(exit_code)

Input In [13], in main()
    108     else:
    109         config['main']['force_onebit'] = True
--> 111     plugins = build_plugin_list(config=config, resolution=screen.resolution, cache=cache)
    113 #     return plugins, screen, cache
    115     exit_code = update_loop(plugins=plugins, screen=screen, max_refresh=config['main']['max_refresh'])

Input In [18], in build_plugin_list(config, resolution, cache)
     71     logging.warning(f'skipping plugin')
     72     continue
---> 73 my_plugin = Plugin(**my_config)
     74 try:
     75     my_plugin.update()

File ~/src/epd_display/paperpi/library/Plugin.py:94, in Plugin.__init__(self, resolution, name, layout, update_function, max_priority, refresh_rate, min_display_time, config, cache, force_onebit, **kwargs)
     91         if resolution:
     92             self.resolution = resolution
---> 94         self.layout = layout
     96 #         if update_function:
     97 #             self._add_update_function(update_function)
     98 #         else:
     99 # #             self.update_function = print('no update function set')
    100 #             pass
    101         self.update_function = update_function

File ~/src/epd_display/paperpi/library/Plugin.py:42, in strict_enforce.<locals>.decorator.<locals>.new_f(self, *args, **kwds)
     40                     raise TypeError(f'"{a}" is not type {t}')
     41 #                 newargs.append( t(a)) #feel free to have more elaborated convertion
---> 42             return f(self, *args, **kwds)

File ~/src/epd_display/paperpi/library/Plugin.py:159, in Plugin.layout(self, layout)
    156 @layout.setter
    157 @strict_enforce(dict)
    158 def layout(self, layout):
--> 159     self.layout_obj = Layout(resolution=self.resolution, layout=layout, force_onebit=self.force_onebit)

File ~/.local/share/virtualenvs/epd_display-ApAYs8Kw/lib/python3.9/site-packages/epdlib/Layout.py:77, in Layout.__init__(self, resolution, layout, force_onebit)
     75 self.mode = '1'
     76 self.blocks = {}
---> 77 self.layout = layout

File ~/.local/share/virtualenvs/epd_display-ApAYs8Kw/lib/python3.9/site-packages/epdlib/Layout.py:62, in strict_enforce.<locals>.decorator.<locals>.new_f(self, *args, **kwds)
     60                     raise TypeError(f'"{a}" is not type {t}')
     61 #                 newargs.append( t(a)) #feel free to have more elaborated convertion
---> 62             return f(self, *args, **kwds)

File ~/.local/share/virtualenvs/epd_display-ApAYs8Kw/lib/python3.9/site-packages/epdlib/Layout.py:105, in Layout.layout(self, layout)
    103 if self._layout:
    104     self._add_defaults()
--> 105     self._calculate_layout()
    106     self._set_blocks()

File ~/.local/share/virtualenvs/epd_display-ApAYs8Kw/lib/python3.9/site-packages/epdlib/Layout.py:209, in Layout._calculate_layout(self)
    206 values['padded_area'] = padded_area
    208 if values['type'] == 'TextBlock':
--> 209     values['font_size'] = self._scale_font(values)
    212 if values['abs_coordinates'][0] is None or values['abs_coordinates'][1] is None:
    213     logging.debug('calculating block position from relative positions')

File ~/.local/share/virtualenvs/epd_display-ApAYs8Kw/lib/python3.9/site-packages/epdlib/Layout.py:250, in Layout._scale_font(self, this_section)
    248 while cont:
    249     fontsize += 1
--> 250     testfont = ImageFont.truetype(font, fontsize)
    252     fontdim = testfont.getsize(text)
    254     if fontdim[0] > x_target:

File ~/.local/share/virtualenvs/epd_display-ApAYs8Kw/lib/python3.9/site-packages/PIL/ImageFont.py:844, in truetype(font, size, index, encoding, layout_engine)
    841     return FreeTypeFont(font, size, index, encoding, layout_engine)
    843 try:
--> 844     return freetype(font)
    845 except OSError:
    846     if not isPath(font):

File ~/.local/share/virtualenvs/epd_display-ApAYs8Kw/lib/python3.9/site-packages/PIL/ImageFont.py:841, in truetype.<locals>.freetype(font)
    840 def freetype(font):
--> 841     return FreeTypeFont(font, size, index, encoding, layout_engine)

File ~/.local/share/virtualenvs/epd_display-ApAYs8Kw/lib/python3.9/site-packages/PIL/ImageFont.py:193, in FreeTypeFont.__init__(self, font, size, index, encoding, layout_engine)
    191                 load_from_bytes(f)
    192             return
--> 193     self.font = core.getfont(
    194         font, size, index, encoding, layout_engine=layout_engine
    195     )
    196 else:
    197     load_from_bytes(font)

OSError: cannot open resource

@txoof txoof changed the title handle exception for missing fonts -- causes crach handle exception for missing fonts -- causes crash Feb 3, 2022
@txoof txoof transferred this issue from txoof/epd_display Nov 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant