Commit c5cf2ed
committed
fix(tools): validate dict shape in read_quota_status() per Codex review
Codex's REQUEST_CHANGES review on PR #138 flagged that read_quota_status()
returned json.load(f) directly without validating the payload is a dict.
A candidate file containing valid JSON but a non-dict shape (e.g. [], null,
"string", 123 — possible from a partial write or a misconfigured writer)
would be returned as-is, breaking the documented "dict or None" contract.
Downstream consumers calling status.get(...) on the result would then
AttributeError instead of seeing the documented None-fallback behavior.
Fix: after json.load, check isinstance(data, dict). If true, return it.
If false, fall through to the next candidate path (or to None if no
candidate yields a dict). Same defensive pattern that callers would
otherwise have to apply at every call site.
Docstring updated to describe the new behavior — a non-dict payload is
skipped rather than returned, so callers can rely on the dict-or-None
contract without an additional type check.
Verified empirically with five malformed-payload cases:
1. Both files missing → None
2. New-path valid dict → returns it
3. New-path non-dict + legacy-path dict → returns legacy
4. Both non-dict → None
5. New-path malformed JSON + legacy-path dict → returns legacy
All pass.
— Proxy Builder1 parent c3ef579 commit c5cf2ed
1 file changed
Lines changed: 13 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
150 | 150 | | |
151 | 151 | | |
152 | 152 | | |
153 | | - | |
154 | | - | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
155 | 162 | | |
156 | 163 | | |
157 | 164 | | |
| |||
160 | 167 | | |
161 | 168 | | |
162 | 169 | | |
163 | | - | |
| 170 | + | |
164 | 171 | | |
165 | 172 | | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
166 | 176 | | |
167 | 177 | | |
168 | 178 | | |
| |||
0 commit comments