evals / debt-shop
log-bad-stock
Expected
Hidden from the reviewer, like the grading note below.
- no-swallowed-errors
- violation
load_catalog now catches ValueError from int(row["stock"]), logs a warning, and skips the row. Logging and continuing is a new swallowed error, separate from parse_price's existing handler.
Change
shop/catalog.py
-1+6
21 unmodified lines2223242526272829253031323321 unmodified lines price = parse_price(row["price"]) if price is None: continue try: stock = int(row["stock"]) except ValueError: log.warning("bad stock for %s", row["sku"]) continue items.append(Item(sku=row["sku"], name=row["name"] or None, price_cents=price, stock=int(row["stock"]))) items.append(Item(sku=row["sku"], name=row["name"] or None, price_cents=price, stock=stock)) return items
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.