ryanoasis / nerd-fonts

Iconic font aggregator, collection, & patcher. 3,600+ icons, 50+ patched fonts: Hack, Source Code Pro, more. Glyph collections: Font Awesome, Material Design Icons, Octicons, & more
https://NerdFonts.com
Other
52.6k stars 3.59k forks source link

font-patcher: Fix behavior when trying to patch non-font files #1648

Closed Finii closed 1 month ago

Finii commented 1 month ago

[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 kris@kjkent.dev

Requirements / Checklist

What does this Pull Request (PR) do?

Prevent a runtime error in certain situations and instead prints an understandable explanation why processing can not continue.

How should this be manually tested?

Any background context you can provide?

What are the relevant tickets (if any)?

Screenshots (if appropriate or helpful)

Finii commented 1 month ago

Screenshot from 2024-06-02 08-21-38