diff --git a/changelog.d/20250826_171614_salome.voltz_scrt_5812_investigate_ggshield_running_into_an_ownership_issue_in_git.md b/changelog.d/20250826_171614_salome.voltz_scrt_5812_investigate_ggshield_running_into_an_ownership_issue_in_git.md new file mode 100644 index 0000000000..6033f2348d --- /dev/null +++ b/changelog.d/20250826_171614_salome.voltz_scrt_5812_investigate_ggshield_running_into_an_ownership_issue_in_git.md @@ -0,0 +1,42 @@ + + + + + + + +### Fixed + +- Extend the range of API error status code supported by ggshield so the UI correctly displays them. + + diff --git a/ggshield/core/errors.py b/ggshield/core/errors.py index 2348912d66..ef79d9a9da 100644 --- a/ggshield/core/errors.py +++ b/ggshield/core/errors.py @@ -213,3 +213,7 @@ def handle_api_error(detail: Detail) -> None: raise UnexpectedError(f"Scanning failed: {detail.detail}") if detail.status_code == 403 and detail.detail == "Quota limit reached.": raise QuotaLimitReachedError() + if detail.status_code == 400 and "not found" in detail.detail: + raise UnexpectedError(detail.detail) + if 500 <= detail.status_code < 600: + raise ServiceUnavailableError(detail.detail) diff --git a/ggshield/verticals/secret/secret_scanner.py b/ggshield/verticals/secret/secret_scanner.py index bfb840ae92..e323eee8ca 100644 --- a/ggshield/verticals/secret/secret_scanner.py +++ b/ggshield/verticals/secret/secret_scanner.py @@ -231,7 +231,7 @@ def handle_scan_chunk_error(detail: Detail, chunk: List[Scannable]) -> None: details = None # Handle source_uuid not found error specifically - if "Source not found" in detail.detail: + if "Source" in detail.detail and "not found" in detail.detail: ui.display_error("The provided source was not found in GitGuardian.") return diff --git a/tests/unit/verticals/secret/__snapshots__/test_secret_scanner.ambr b/tests/unit/verticals/secret/__snapshots__/test_secret_scanner.ambr index 48517b1ba9..9fba0b693e 100644 --- a/tests/unit/verticals/secret/__snapshots__/test_secret_scanner.ambr +++ b/tests/unit/verticals/secret/__snapshots__/test_secret_scanner.ambr @@ -7,12 +7,6 @@ ''' # --- -# name: test_handle_scan_error[source not found] - ''' - Error: The provided source was not found in GitGuardian. - - ''' -# --- # name: test_handle_scan_error[too many documents] ''' Error: Scanning failed. Results may be incomplete. diff --git a/tests/unit/verticals/secret/test_secret_scanner.py b/tests/unit/verticals/secret/test_secret_scanner.py index 077975987b..53cba34f1f 100644 --- a/tests/unit/verticals/secret/test_secret_scanner.py +++ b/tests/unit/verticals/secret/test_secret_scanner.py @@ -200,21 +200,21 @@ def test_handle_scan_error_api_key(): ], id="single file exception", ), - pytest.param( - Detail("Source not found"), - 400, - [StringScannable(content="test", url="test.txt")], - id="source not found", - ), ], ) def test_handle_scan_error(detail, status_code, chunk, capsys, snapshot): - detail.status_code = 400 + detail.status_code = status_code handle_scan_chunk_error(detail, chunk) captured = capsys.readouterr() assert captured.err == snapshot +def test_scan_source_uuid_not_found(): + detail = Detail(detail="Source not found.", status_code=400) + with pytest.raises(UnexpectedError): + handle_scan_chunk_error(detail, Mock()) + + def test_handle_scan_quota_limit_reached(): detail = Detail(detail="Quota limit reached.", status_code=403) with pytest.raises(QuotaLimitReachedError):