diff --git a/ggshield/secret/secret_scanner.py b/ggshield/secret/secret_scanner.py index adf04e64f9..fe42569311 100644 --- a/ggshield/secret/secret_scanner.py +++ b/ggshield/secret/secret_scanner.py @@ -209,9 +209,6 @@ def _collect_results( ) if not scan.success: - if scan.status_code == 403 and scan.detail == "Quota limit reached.": - raise QuotaLimitReachedError() - handle_scan_chunk_error(scan, chunk) continue @@ -241,6 +238,8 @@ def handle_scan_chunk_error(detail: Detail, chunk: List[Scannable]) -> None: raise click.UsageError(detail.detail) if detail.status_code is None: raise UnexpectedError(f"Scanning failed: {detail.detail}") + if detail.status_code == 403 and detail.detail == "Quota limit reached.": + raise QuotaLimitReachedError() details = None diff --git a/tests/unit/secret/test_secret_scanner.py b/tests/unit/secret/test_secret_scanner.py index a2aa39ef26..f790d766f5 100644 --- a/tests/unit/secret/test_secret_scanner.py +++ b/tests/unit/secret/test_secret_scanner.py @@ -5,7 +5,7 @@ import pytest from pygitguardian.models import Detail -from ggshield.core.errors import ExitCode +from ggshield.core.errors import ExitCode, QuotaLimitReachedError from ggshield.core.git_shell import Filemode from ggshield.scan import ( Commit, @@ -186,3 +186,9 @@ def test_handle_scan_error(detail, status_code, chunk, capsys, snapshot): handle_scan_chunk_error(detail, chunk) captured = capsys.readouterr() snapshot.assert_match(captured.err) + + +def test_handle_scan_quota_limit_reached(): + detail = Detail(detail="Quota limit reached.", status_code=403) + with pytest.raises(QuotaLimitReachedError): + handle_scan_chunk_error(detail, Mock())