Commit a6957fa
committed
fix(scraper): replace misleading 403 hint for AI Scraper Studio errors
When a `bdata scraper create` succeeds on the template POST but the
subsequent AI-trigger POST 429s (e.g. because the user hit the AI Flow
parallel-job cap), the half-built `collector_id` is still printed.
If that id is then passed to `bdata scraper run`, the API returns
403 + body `{"error":"Collector does not have a template"}`.
Today the CLI maps any 403 to a fixed hint:
Hint: Access denied. Check your zone permissions in the control
panel.
This sends the user 30+ minutes down a zone-permission rabbit hole
that has nothing to do with the actual problem (the AI Flow never
finished generating selectors for this collector). Observed multiple
times during stress testing.
This change is structured so the AI Scraper Studio error vocabulary
stays in the scraper command and does NOT leak into the shared HTTP
client. `scrape`, `search`, `discover`, `pipelines`, and `browser`
are unaffected.
Mechanism:
* `src/utils/client.ts` gains a generic `hints?: Body_hint[]` field
on `Request_opts`. The pure helper `pick_hint(status, body, hints)`
consults the caller's list first and falls back to the existing
`ERROR_HINTS` status-code map. The shared client ships ZERO
command-specific patterns.
* `src/commands/scraper.ts` defines `SCRAPER_BODY_HINTS` — two
patterns:
- /collector does not have a template/i → AI generation didn't
complete; re-run `scraper create`; web-UI URL for manual
recovery.
- /cannot run more than \d+ jobs in parallel/i → AI-Flow
concurrent-job cap; serialise launches.
Every `post`/`get` call in `handle_create_scraper`,
`handle_run_scraper`, and `run_batch` passes `hints:
SCRAPER_BODY_HINTS` so a 4xx from any of them is translated with
the right vocabulary.
* Real zone-permission 403s (any body that doesn't match the
scraper patterns) still get the original "Access denied" hint —
test 'does not consult ERROR_HINTS when an extra-hint pattern
matches' locks this in.
Tests: 8 unit tests for `client.pick_hint` using mock generic
patterns (covers mechanism + asserts the shared client carries no
scraper vocabulary in ERROR_HINTS), plus 5 scraper command tests
asserting the scraper patterns are well-formed and travel via
`hints` to client.post on every AI-Flow call. Two existing tests
relaxed from strict opts-object matches to objectContaining-style.
58 / 58 tests in the affected files pass. The 9 pre-existing
failures in unrelated suites (daemon, add-mcp, browser, discover,
scrape) on main are unchanged by this PR.1 parent fadfc2b commit a6957fa
4 files changed
Lines changed: 232 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
| 61 | + | |
61 | 62 | | |
62 | 63 | | |
63 | 64 | | |
| |||
68 | 69 | | |
69 | 70 | | |
70 | 71 | | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
71 | 151 | | |
72 | 152 | | |
73 | 153 | | |
| |||
176 | 256 | | |
177 | 257 | | |
178 | 258 | | |
179 | | - | |
| 259 | + | |
180 | 260 | | |
181 | 261 | | |
182 | 262 | | |
183 | 263 | | |
184 | 264 | | |
185 | 265 | | |
186 | 266 | | |
187 | | - | |
| 267 | + | |
188 | 268 | | |
189 | 269 | | |
190 | 270 | | |
| |||
404 | 484 | | |
405 | 485 | | |
406 | 486 | | |
407 | | - | |
| 487 | + | |
408 | 488 | | |
409 | 489 | | |
410 | 490 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
21 | 52 | | |
22 | 53 | | |
23 | 54 | | |
| |||
105 | 136 | | |
106 | 137 | | |
107 | 138 | | |
108 | | - | |
| 139 | + | |
109 | 140 | | |
110 | 141 | | |
111 | 142 | | |
| |||
129 | 160 | | |
130 | 161 | | |
131 | 162 | | |
132 | | - | |
| 163 | + | |
133 | 164 | | |
134 | 165 | | |
135 | 166 | | |
| |||
148 | 179 | | |
149 | 180 | | |
150 | 181 | | |
151 | | - | |
| 182 | + | |
152 | 183 | | |
153 | 184 | | |
154 | 185 | | |
| |||
338 | 369 | | |
339 | 370 | | |
340 | 371 | | |
341 | | - | |
| 372 | + | |
342 | 373 | | |
343 | 374 | | |
344 | 375 | | |
| |||
474 | 505 | | |
475 | 506 | | |
476 | 507 | | |
477 | | - | |
| 508 | + | |
478 | 509 | | |
479 | 510 | | |
480 | 511 | | |
| |||
592 | 623 | | |
593 | 624 | | |
594 | 625 | | |
| 626 | + | |
595 | 627 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
14 | 36 | | |
15 | 37 | | |
16 | 38 | | |
17 | 39 | | |
18 | 40 | | |
19 | 41 | | |
| 42 | + | |
20 | 43 | | |
21 | 44 | | |
22 | 45 | | |
| |||
27 | 50 | | |
28 | 51 | | |
29 | 52 | | |
30 | | - | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
31 | 58 | | |
32 | 59 | | |
33 | | - | |
| 60 | + | |
34 | 61 | | |
35 | 62 | | |
36 | 63 | | |
| |||
93 | 120 | | |
94 | 121 | | |
95 | 122 | | |
96 | | - | |
| 123 | + | |
97 | 124 | | |
98 | 125 | | |
99 | 126 | | |
| |||
133 | 160 | | |
134 | 161 | | |
135 | 162 | | |
136 | | - | |
137 | | - | |
| 163 | + | |
| 164 | + | |
0 commit comments