Skip to content

Commit

Permalink
fixup! feat(quota): #309 Improve handling of "quota limit reached" er…
Browse files Browse the repository at this point in the history
…rors
  • Loading branch information
Walz committed Jul 5, 2023
1 parent 0629315 commit 4f0ccbc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 2 additions & 3 deletions ggshield/secret/secret_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
8 changes: 7 additions & 1 deletion tests/unit/secret/test_secret_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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())

0 comments on commit 4f0ccbc

Please sign in to comment.