Fix #1160: Replace broad except Exception with specific exception typ…#1161
Merged
jonbrenas merged 3 commits intomalariagen:masterfrom Mar 20, 2026
Merged
Conversation
…es in phenotypes.py The code had 5 instances of except Exception that silently converted real bugs into warnings, returning empty/partial data. This is dangerous for scientific analysis where data correctness is critical. Changes: - Site 1 (_load_phenotype_data): Narrowed to (KeyError, FileNotFoundError, IOError) - Site 2 (_create_phenotype_dataset): Removed redundant catch-all (KeyError and ValueError were already caught above) - Site 3 (phenotype_data): Removed try/except around sample_metadata() — let errors from the upstream API propagate naturally - Site 4 (phenotype_data query): Narrowed to (pd.errors.UndefinedVariableError, SyntaxError) for malformed queries - Site 5 (phenotype_sample_sets): Narrowed to (KeyError, FileNotFoundError)
Collaborator
|
Thanks @khushthecoder, |
jonbrenas
approved these changes
Mar 20, 2026
Contributor
Author
|
Thank you for the review and approval @jonbrenas! Really appreciate it. Feel free to merge whenever convenient. |
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.
Fix #1160: Replace broad
except Exceptionwith specific exception types inphenotypes.pyFixes: #1160
Summary
phenotypes.pyhad 5 instances ofexcept Exceptionthat silently converted real bugs (TypeError, KeyError, AttributeError, etc.) into warnings, returning empty or partial data. This is dangerous for scientific analysis where data correctness is critical.Changes
_load_phenotype_data()outer loop(KeyError, FileNotFoundError, IOError)_create_phenotype_dataset()variant mergeKeyErrorandValueErroralready caught abovephenotype_data()metadata fetchtry/except— letsample_metadata()errors propagate naturallyphenotype_data()query evaluation(pd.errors.UndefinedVariableError, SyntaxError)phenotype_sample_sets()path check(KeyError, FileNotFoundError)Design rationale
TypeErrororAttributeErroris a real bug that should crash with a traceback, not get silently converted into a warningFileNotFoundErrorwhen a sample set has no phenotype data,KeyErrorwhen a sample set has no release mapping, andUndefinedVariableErrorfor bad user queries are all expected and still handled gracefully