Skip to content

Commit b3d357e

Browse files
committed
fix(errors): extend error status code supported by ggshield
1 parent ef7aa67 commit b3d357e

File tree

4 files changed

+54
-8
lines changed

4 files changed

+54
-8
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/test_secret_scanner.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -200,16 +200,10 @@ 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
@@ -221,6 +215,12 @@ def test_handle_scan_quota_limit_reached():
221215
handle_scan_chunk_error(detail, Mock())
222216

223217

218+
def test_scan_source_uuid_not_found():
219+
detail = Detail(detail="Source not found.", status_code=400)
220+
with pytest.raises(UnexpectedError):
221+
handle_scan_chunk_error(detail, Mock())
222+
223+
224224
def test_scan_merge_commit(client, cache):
225225
"""
226226
GIVEN a merge commit in which a secret was inserted

0 commit comments

Comments
 (0)