Commit 00f9a4f
chore: improve metadata service error handling (#1902)
Improved error handling in `google/auth/compute_engine/_metadata.py` to
provide more informative error messages when retries are exhausted.
The logic now handles two distinct failure modes:
1. **Connection Errors (Exceptions):**
- Exceptions caught during the request (e.g., connection refused) are
stored in `last_exception`.
- If the retry loop exhausts and `last_exception` is set, a
`TransportError` is raised that chains the original exception. This
preserves the stack trace and specific error type for debugging.
2. **Retryable HTTP Status Codes:**
- If a request completes but returns a retryable status code (e.g., 500,
503), `last_exception` is cleared (set to `None`).
- If the retry loop exhausts due to repeated retryable status codes, a
`TransportError` is raised that includes the `response.status` and the
response body (`error_details`). This ensures the specific server error
message is visible.
This addresses feedback from PR 1637 by ensuring that "Ran out of
retries" scenarios provide the most relevant context: either the
underlying exception or the final HTTP error response.
---
*PR created automatically by Jules for task
[6226991344715693997](https://jules.google.com/task/6226991344715693997)
started by @chalmerlowe*
---------
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Co-authored-by: Chalmer Lowe <chalmerlowe@google.com>1 parent 5d00147 commit 00f9a4f
File tree
2 files changed
+24
-14
lines changed- google/auth/compute_engine
- tests/compute_engine
2 files changed
+24
-14
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
294 | 294 | | |
295 | 295 | | |
296 | 296 | | |
297 | | - | |
| 297 | + | |
298 | 298 | | |
299 | 299 | | |
300 | 300 | | |
| |||
308 | 308 | | |
309 | 309 | | |
310 | 310 | | |
311 | | - | |
312 | | - | |
313 | | - | |
314 | | - | |
315 | | - | |
| 311 | + | |
316 | 312 | | |
317 | 313 | | |
| 314 | + | |
318 | 315 | | |
319 | 316 | | |
320 | 317 | | |
| |||
325 | 322 | | |
326 | 323 | | |
327 | 324 | | |
328 | | - | |
| 325 | + | |
329 | 326 | | |
330 | | - | |
331 | | - | |
332 | | - | |
333 | | - | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
334 | 345 | | |
335 | | - | |
336 | 346 | | |
337 | 347 | | |
338 | 348 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
407 | 407 | | |
408 | 408 | | |
409 | 409 | | |
410 | | - | |
| 410 | + | |
411 | 411 | | |
412 | 412 | | |
413 | 413 | | |
| |||
426 | 426 | | |
427 | 427 | | |
428 | 428 | | |
429 | | - | |
| 429 | + | |
430 | 430 | | |
431 | 431 | | |
432 | 432 | | |
| |||
0 commit comments