Skip to content

fix: replace 2 bare except clauses with except Exception - #1293

Open
KeloYuan wants to merge 1 commit into
mandiant:masterfrom
KeloYuan:fix/bare-except-improvements
Open

fix: replace 2 bare except clauses with except Exception#1293
KeloYuan wants to merge 1 commit into
mandiant:masterfrom
KeloYuan:fix/bare-except-improvements

Conversation

@KeloYuan

@KeloYuan KeloYuan commented May 8, 2026

Copy link
Copy Markdown

Replaces 2 bare except: with except Exception: in floss/utils.py and floss/language/identify.py.

Changed: floss/utils.py, floss/language/identify.py
@google-cla

google-cla Bot commented May 8, 2026

Copy link
Copy Markdown

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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
except Exception:
except IndexError:
References
  1. PEP 8 recommends mentioning specific exceptions whenever possible instead of using a broad exception handler like except Exception: or a bare except:. (link)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant