Skip to content

Commit

Permalink
font-patcher: Fix behavior when trying to patch non-font files
Browse files Browse the repository at this point in the history
[why]
When the file specified to be patched is not a font file the patcher run
errors out with an out of index runtime error:

Traceback (most recent call last):
  File "/home/fini/extra/git/nerd-fonts/font-patcher", line 2155, in <module>
    main()
  File "/home/fini/extra/git/nerd-fonts/font-patcher", line 2147, in main
    patcher.generate(sourceFonts)
  File "/home/fini/extra/git/nerd-fonts/font-patcher", line 415, in generate
    sourceFont = sourceFonts[0]
                 ~~~~~~~~~~~^^^
IndexError: list index out of range

[how]
Do not assume that the specified file will be a font file but rather
check if fontforge detects a font in the file and error out if there is
no font found.

Fixes: #1647

Reported-by: Kristopher James Kent <[email protected]>
Signed-off-by: Fini Jastrow <[email protected]>
  • Loading branch information
Finii committed Jun 2, 2024
1 parent f647334 commit e7f6a4f
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions font-patcher
Original file line number Diff line number Diff line change
Expand Up @@ -2127,6 +2127,9 @@ def main():

sourceFonts = []
all_fonts = fontforge.fontsInFile(args.font)
if not all_fonts:
logger.critical("Can not find any fonts in '%s'", args.font)
sys.exit(1)
for i, subfont in enumerate(all_fonts):
if len(all_fonts) > 1:
print("\n")
Expand Down

0 comments on commit e7f6a4f

Please sign in to comment.