Return False from isValidFont for a missing font (#156)#161
Open
apoorvdarshan wants to merge 1 commit into
Open
Return False from isValidFont for a missing font (#156)#161apoorvdarshan wants to merge 1 commit into
apoorvdarshan wants to merge 1 commit into
Conversation
isValidFont raised FileNotFoundError for a .flf/.tlf-named font that does not exist (the fallback opens a package resource that may be absent), instead of reporting the font as invalid. Catch FileNotFoundError and return False so the validity check does not crash. Fixes pwaller#156.
Owner
|
I just landed #158 which conflicts with the PR you sent. Can you ask your AI to rebase against it and fix up the conflicts? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #156.
Problem
FigletFont.isValidFont(font)is a validity predicate, but it raisesFileNotFoundErrorfor a.flf/.tlf-named font that doesn't exist, instead of returningFalse:When the font is neither a local file, nor in
SHARED_DIRECTORY, nor a bundled package resource, the fallback...joinpath(font).open('rb')raises. Callers reasonably expectisValidFontto simply returnFalsefor an unknown font.Fix
Wrap the font-opening in
try/except FileNotFoundErrorand returnFalsewhen the font can't be found:Testing
test_is_valid_font_missing:isValidFont("does_not_exist.flf")and.tlfreturnFalse(no exception), and a real bundled font (standard.flf) is still recognized as valid. It fails onmaster(raisesFileNotFoundError) and passes with this change.4 passedwith thepyfigletentry point onPATH; the CLI subprocess tests need it there, which is a pre-existing environment requirement unrelated to this change).Disclosure: this change was prepared with the assistance of an AI tool (Claude Code). I reproduced the issue, implemented and verified the fix and test, and take responsibility for the contribution and will respond to review feedback personally.