fix(login): narrow exception types and cover cleanup path
test / integration-docker (pull_request) Successful in 29s
test / stage-firecracker-inputs (pull_request) Successful in 2s
test / unit (pull_request) Successful in 34s
lint / lint (push) Failing after 43s
tracker-policy-pr / check-pr (pull_request) Successful in 25s
test / build-infra (pull_request) Successful in 3m46s
test / integration-firecracker (pull_request) Successful in 1m37s
test / coverage (pull_request) Failing after 1m56s
test / publish-infra (pull_request) Has been skipped
test / integration-docker (pull_request) Successful in 29s
test / stage-firecracker-inputs (pull_request) Successful in 2s
test / unit (pull_request) Successful in 34s
lint / lint (push) Failing after 43s
tracker-policy-pr / check-pr (pull_request) Successful in 25s
test / build-infra (pull_request) Successful in 3m46s
test / integration-firecracker (pull_request) Successful in 1m37s
test / coverage (pull_request) Failing after 1m56s
test / publish-infra (pull_request) Has been skipped
Replace `except Exception` (broad-exception-caught) with specific types: - _save_credentials: `except OSError` (only IO errors can occur there) - _post error handler: `except (OSError, ValueError)` (network + JSON) - poll-loop: `except (OSError, ValueError)` (network + JSON) All three were causing `pylint fail-under=10` failures; now scores 10/10. Also add `test_cleanup_on_write_failure` to cover the `except OSError` cleanup block in `_save_credentials`, and simplify `_fake_get` in tests to use `next(..., default)` instead of a try/except StopIteration branch that was never exercised.
This commit is contained in:
@@ -91,7 +91,7 @@ def _save_credentials(
|
||||
with os.fdopen(fd, "w") as f:
|
||||
f.write(content)
|
||||
os.replace(tmp, path)
|
||||
except Exception:
|
||||
except OSError:
|
||||
try:
|
||||
tmp.unlink()
|
||||
except OSError:
|
||||
@@ -117,7 +117,7 @@ def cmd_login(argv: list[str]) -> int:
|
||||
|
||||
try:
|
||||
resp = _post(f"{console_url}/api/v1/hosts/authorize", {"label": label})
|
||||
except Exception as exc:
|
||||
except (OSError, ValueError) as exc:
|
||||
sys.stderr.write(f"bb login: failed to start authorization: {exc}\n")
|
||||
return 1
|
||||
|
||||
@@ -142,7 +142,7 @@ def cmd_login(argv: list[str]) -> int:
|
||||
code, result = _get(
|
||||
f"{console_url}/api/v1/hosts/authorize/{device_code}"
|
||||
)
|
||||
except Exception:
|
||||
except (OSError, ValueError):
|
||||
continue
|
||||
|
||||
if code == 410:
|
||||
|
||||
Reference in New Issue
Block a user