Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

handle exception for missing fonts -- causes crash

Aperta
#60 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
25/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
python
Ambito
backend

Direzione di ricerca

Start at build_plugin_list, where the traceback shows Plugin(**my_config) is called, and read how plugin-loading exceptions are handled. The failure occurs while Layout scales a font and Pillow raises OSError; the issue suggests catching that error in the loader. Done means a missing font no longer crashes startup.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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

Lingua principale
Python
Stelle
205
Fork
17
Merge medio
6h 12m
PR unite (30g)
44

Preparare l'ambiente

  • Nessun Dockerfile né file Docker Compose
  • Ha un modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di txoof/PaperPi

Tutte le issue di txoof/PaperPi

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.