Skip to content

Commit 998953f

Browse files
authored
Merge pull request #1126 from GitGuardian/salomevoltz/scrt-5746-ggshield-secret-scan-still-shows-scanning-even-if-theres-an
fix(errors): extend error status code supported by ggshield
2 parents ef7aa67 + 07b3633 commit 998953f

File tree

5 files changed

+54
-14
lines changed

5 files changed

+54
-14
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<!--
2+
A new scriv changelog fragment.
3+
4+
Uncomment the section that is right (remove the HTML comment wrapper).
5+
For top level release notes, leave all the headers commented out.
6+
-->
7+
8+
<!--
9+
### Removed
10+
11+
- A bullet item for the Removed category.
12+
13+
-->
14+
<!--
15+
### Added
16+
17+
- A bullet item for the Added category.
18+
19+
-->
20+
<!--
21+
### Changed
22+
23+
- A bullet item for the Changed category.
24+
25+
-->
26+
<!--
27+
### Deprecated
28+
29+
- A bullet item for the Deprecated category.
30+
31+
-->
32+
33+
### Fixed
34+
35+
- Extend the range of API error status code supported by ggshield so the UI correctly displays them.
36+
37+
<!--
38+
### Security
39+
40+
- A bullet item for the Security category.
41+
42+
-->

ggshield/core/errors.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,3 +213,7 @@ def handle_api_error(detail: Detail) -> None:
213213
raise UnexpectedError(f"Scanning failed: {detail.detail}")
214214
if detail.status_code == 403 and detail.detail == "Quota limit reached.":
215215
raise QuotaLimitReachedError()
216+
if detail.status_code == 400 and "not found" in detail.detail:
217+
raise UnexpectedError(detail.detail)
218+
if 500 <= detail.status_code < 600:
219+
raise ServiceUnavailableError(detail.detail)

ggshield/verticals/secret/secret_scanner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ def handle_scan_chunk_error(detail: Detail, chunk: List[Scannable]) -> None:
231231
details = None
232232

233233
# Handle source_uuid not found error specifically
234-
if "Source not found" in detail.detail:
234+
if "Source" in detail.detail and "not found" in detail.detail:
235235
ui.display_error("The provided source was not found in GitGuardian.")
236236
return
237237

tests/unit/verticals/secret/__snapshots__/test_secret_scanner.ambr

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,6 @@
77

88
'''
99
# ---
10-
# name: test_handle_scan_error[source not found]
11-
'''
12-
Error: The provided source was not found in GitGuardian.
13-
14-
'''
15-
# ---
1610
# name: test_handle_scan_error[too many documents]
1711
'''
1812
Error: Scanning failed. Results may be incomplete.

tests/unit/verticals/secret/test_secret_scanner.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -200,21 +200,21 @@ def test_handle_scan_error_api_key():
200200
],
201201
id="single file exception",
202202
),
203-
pytest.param(
204-
Detail("Source not found"),
205-
400,
206-
[StringScannable(content="test", url="test.txt")],
207-
id="source not found",
208-
),
209203
],
210204
)
211205
def test_handle_scan_error(detail, status_code, chunk, capsys, snapshot):
212-
detail.status_code = 400
206+
detail.status_code = status_code
213207
handle_scan_chunk_error(detail, chunk)
214208
captured = capsys.readouterr()
215209
assert captured.err == snapshot
216210

217211

212+
def test_scan_source_uuid_not_found():
213+
detail = Detail(detail="Source not found.", status_code=400)
214+
with pytest.raises(UnexpectedError):
215+
handle_scan_chunk_error(detail, Mock())
216+
217+
218218
def test_handle_scan_quota_limit_reached():
219219
detail = Detail(detail="Quota limit reached.", status_code=403)
220220
with pytest.raises(QuotaLimitReachedError):

0 commit comments

Comments
 (0)