Skip to content

fix(quota-tracker): narrow bare-except to ImportError so real errors propagate - #1300

Closed
sonichi wants to merge 2 commits into
mainfrom
fix/quota-tracker-bare-except
Closed

sonichi wants to merge 2 commits into
mainfrom
fix/quota-tracker-bare-except

Conversation

@sonichi

@sonichi sonichi commented May 28, 2026

Copy link
Copy Markdown
Owner

Summary

  • except Exception in read-quota.py silently swallowed any runtime error from workspace_default, producing a misleading "No quota-state.json found" message
  • Narrowed to except ImportError — the only expected failure (module not on sys.path); all other exceptions now propagate to cron logs
  • Added 3 tests verifying: ImportError sets _canonical = None, non-ImportError propagates, and source no longer contains except Exception:

Closes #1062

Test plan

  • python3 tests/quota-tracker-import-guard.test.py → 3 tests pass
  • Deploy and verify cron pass logs surface real errors instead of "not found"

🤖 Generated with Claude Code

sonichi and others added 2 commits May 27, 2026 23:57
Per Lucy's #1055 review: the bare `except Exception:` on line 26 masked the
path off-by-one for half a day. An `ImportError` is the only expected failure
here — `workspace_default` not importable (wrong sys.path). Narrowing to
`ImportError` lets unexpected exceptions (AttributeError, TypeError, disk
failure) surface to the caller instead of silently setting `_canonical = None`
and printing a misleading 'not found' message.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…propagate

The broad `except Exception` swallowed runtime errors from workspace_default
(e.g. a future refactor raising an unexpected exception type), silently setting
`_canonical = None` and producing the misleading "No quota-state.json found"
message instead of the real cause.

Narrows the guard to `except ImportError` — the only expected failure mode
(workspace_default not on sys.path). Any other exception now propagates and
surfaces in cron pass logs.

Closes #1062

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Chi seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@sonichi

sonichi commented May 28, 2026

Copy link
Copy Markdown
Owner Author

Closing as duplicate of #1094 (VasiliyRad already covers this — same single-token except ImportError fix, closes #1062). Reviewed #1094 instead.

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.

refactor(quota-tracker): narrow read-quota.py:26 bare-except to ImportError

2 participants