Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

handle exception for missing fonts -- causes crash

未关闭
#60 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
25/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
python
领域
backend

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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

主要语言
Python
星标
205
派生
17
平均合并
3 小时 55 分钟
30 天内合并 PR
77

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 有 Pull Request 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

txoof/PaperPi 的其他 Issue

查看 txoof/PaperPi 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。