fix: replace 2 bare except clauses with except Exception - #1293
Conversation
Changed: floss/utils.py, floss/language/identify.py
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Code Review
This pull request replaces bare except: clauses with except Exception: in floss/language/identify.py and floss/utils.py to improve exception handling. The review feedback suggests using a more specific IndexError in identify.py to avoid masking unrelated programming errors, in accordance with PEP 8 guidelines.
| pc_quanum = section.get_data(pclntab_va + 6, 1)[0] | ||
| pointer_size = section.get_data(pclntab_va + 7, 1)[0] | ||
| except: | ||
| except Exception: |
There was a problem hiding this comment.
While except Exception: is an improvement over a bare except:, it is still quite broad for this context. The most likely failure in this block is an IndexError occurring if get_data returns an empty byte string (e.g., if the offset is out of bounds). Catching Exception can mask unrelated programming errors like NameError or TypeError which would indicate bugs in the code rather than data parsing errors. Following PEP 8, it is recommended to catch the most specific exception possible.
| except Exception: | |
| except IndexError: |
References
- PEP 8 recommends mentioning specific exceptions whenever possible instead of using a broad exception handler like
except Exception:or a bareexcept:. (link)
Replaces 2 bare
except:withexcept Exception:infloss/utils.pyandfloss/language/identify.py.