Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!--
A new scriv changelog fragment.

Uncomment the section that is right (remove the HTML comment wrapper).
For top level release notes, leave all the headers commented out.
-->

<!--
### Removed

- A bullet item for the Removed category.

-->
<!--
### Added

- A bullet item for the Added category.

-->
<!--
### Changed

- A bullet item for the Changed category.

-->
<!--
### Deprecated

- A bullet item for the Deprecated category.

-->

### Fixed

- Extend the range of API error status code supported by ggshield so the UI correctly displays them.

<!--
### Security

- A bullet item for the Security category.

-->
4 changes: 4 additions & 0 deletions ggshield/core/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion ggshield/verticals/secret/secret_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 7 additions & 7 deletions tests/unit/verticals/secret/test_secret_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down