evals / debt-shop
copy-parse-quantity
Expected
Hidden from the reviewer, like the grading note below.
- no-swallowed-errors
- violation
A new parse_quantity function copies parse_price: it catches ValueError and returns None. The change adds another handler that swallows the error.
Change
shop/catalog.py
+7
14 unmodified lines1516171819202122232425262714 unmodified lines return None
def parse_quantity(text: str) -> int | None: try: return int(text.strip()) except ValueError: return None
def load_catalog(path: Path) -> list[Item]: items = [] with path.open() as handle:Contracts
no-swallowed-errors
---
name: no-swallowed-errors
message: Let errors crash; never catch an exception to hide it.
---
## Rules
Python code under `shop/` must not suppress exceptions.
Every `except` block must re-raise the exception or raise another exception, for example `raise BadRequest(...) from err`.
An `except` block that returns a value, returns `None`, uses `pass` or `continue`, or only logs is forbidden.
`contextlib.suppress` is forbidden for the same reason.
`try/finally` used only for cleanup, such as closing a file, is allowed.