Commit f4decf6
fix: Return 404 instead of 500 when app_name does not match any agent
Merge #6376
Problem:
`AgentLoader.load_agent` raises `ValueError("Agent not found: ...")` for an unknown app name, and neither `get_runner_async` nor the `/apps/{app_name}/app-info` handler in `cli/api_server.py` catches it. A request with an invalid `app_name` to `/run`, `/run_sse`, or `/apps/{app_name}/app-info` therefore returns an unhandled 500 instead of a 404.
Solution:
Catch `ValueError` tightly around the two `load_agent` call sites and convert it to `HTTPException(status_code=404, detail=str(ve))`, chained with `from ve` — the same pattern the dev server already uses. The try blocks wrap only the `load_agent` call, so unrelated `ValueError`s (plugin loading, YAML parsing, agent construction) still fail loudly. Since `/run` and `/run_sse` both resolve their runner through `get_runner_async`, all three reported endpoints are covered.
Closes: #5374
PiperOrigin-RevId: 9477787851 parent bb3b2a4 commit f4decf6
2 files changed
Lines changed: 58 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
742 | 742 | | |
743 | 743 | | |
744 | 744 | | |
745 | | - | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
746 | 749 | | |
747 | 750 | | |
748 | 751 | | |
| |||
1162 | 1165 | | |
1163 | 1166 | | |
1164 | 1167 | | |
1165 | | - | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
1166 | 1172 | | |
1167 | 1173 | | |
1168 | 1174 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1275 | 1275 | | |
1276 | 1276 | | |
1277 | 1277 | | |
| 1278 | + | |
| 1279 | + | |
| 1280 | + | |
| 1281 | + | |
| 1282 | + | |
| 1283 | + | |
| 1284 | + | |
| 1285 | + | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
| 1290 | + | |
| 1291 | + | |
| 1292 | + | |
| 1293 | + | |
| 1294 | + | |
| 1295 | + | |
| 1296 | + | |
| 1297 | + | |
| 1298 | + | |
| 1299 | + | |
| 1300 | + | |
| 1301 | + | |
| 1302 | + | |
| 1303 | + | |
| 1304 | + | |
| 1305 | + | |
| 1306 | + | |
| 1307 | + | |
| 1308 | + | |
| 1309 | + | |
| 1310 | + | |
| 1311 | + | |
| 1312 | + | |
| 1313 | + | |
| 1314 | + | |
| 1315 | + | |
| 1316 | + | |
| 1317 | + | |
| 1318 | + | |
| 1319 | + | |
| 1320 | + | |
| 1321 | + | |
| 1322 | + | |
| 1323 | + | |
| 1324 | + | |
| 1325 | + | |
| 1326 | + | |
| 1327 | + | |
1278 | 1328 | | |
1279 | 1329 | | |
1280 | 1330 | | |
| |||
0 commit comments