Commit 5c0a26d
fix(canary): post_json error handling + robust Haiku JSON extraction
Address gemini-code-assist review on scripts/live-canary/notify_slack.py:
1. `post_json` unreachable error branch: `urllib.request.urlopen`
raises `urllib.error.HTTPError` for 4xx/5xx before reaching the
`if resp.status >= 300` check, so the error body was never
surfaced. Wrap in try/except and read the body from the
HTTPError instance — that's where Anthropic's "invalid API key"
/ "rate limited" detail lives.
2. Haiku JSON extraction was fragile: `startswith("```")` assumed
the response had no prose preamble and only handled one fence
shape. Replace with `re.search(r"\{.*\}", text, re.DOTALL)` so
we pick the outermost JSON object regardless of any wrapper
markdown or leading/trailing text. Greedy + DOTALL is correct
for the single top-level object our schema requires.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 4bd69b1 commit 5c0a26d
1 file changed
Lines changed: 24 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
132 | 133 | | |
133 | 134 | | |
134 | 135 | | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
143 | 148 | | |
144 | 149 | | |
145 | 150 | | |
| |||
175 | 180 | | |
176 | 181 | | |
177 | 182 | | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
182 | 192 | | |
183 | | - | |
| 193 | + | |
184 | 194 | | |
185 | | - | |
| 195 | + | |
186 | 196 | | |
187 | 197 | | |
188 | 198 | | |
| |||
0 commit comments