Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

handle exception for missing fonts -- causes crash

Đang mở
#60 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
25/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
python
Lĩnh vực
backend

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

Ngôn ngữ chính
Python
Star
205
Fork
17
Merge trung bình
6 giờ 12 phút
Pull request đã merge (30 ngày)
44

Chuẩn bị môi trường

  • Không có Dockerfile hay tệp Docker Compose
  • Có mẫu pull request
  • Không có hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của txoof/PaperPi

Tất cả issue của txoof/PaperPi

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.