Skip to content

Commit b9a842b

Browse files
authored
Raise a MatchCodeIOException for invalid responses from MatchCode.io #1665 (#1666)
Signed-off-by: tdruez <tdruez@nexb.com>
1 parent 83695a5 commit b9a842b

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

CHANGELOG.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
Changelog
22
=========
33

4+
v34.12.0 (unreleased)
5+
---------------------
6+
7+
- Raise a ``MatchCodeIOException`` when the response from the MatchCode.io service is
8+
not valid in ``send_project_json_to_matchcode``.
9+
This generally means an issue on the MatchCode.io server side.
10+
https://github.com/aboutcode-org/scancode.io/issues/1665
11+
412
v34.11.0 (2025-05-02)
513
---------------------
614

scanpipe/pipelines/match_to_matchcode.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ def check_matchcode_service_availability(self):
6363
"related settings to a MatchCode.io instance or reach out "
6464
"to the maintainers for other arrangements."
6565
)
66-
raise Exception(msg)
66+
raise matchcode.MatchCodeIOException(msg)
6767

6868
if not matchcode.is_available():
69-
raise Exception("MatchCode.io is not available.")
69+
raise matchcode.MatchCodeIOException("MatchCode.io is not available.")
7070

7171
def send_project_json_to_matchcode(self):
7272
"""Create a JSON scan of the project Codebase and send it to MatchCode.io."""

scanpipe/pipes/matchcode.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,10 @@ def send_project_json_to_matchcode(
314314
timeout=timeout,
315315
files=files,
316316
)
317+
318+
if not response:
319+
raise MatchCodeIOException("Invalid response from MatchCode.io")
320+
317321
match_url = response["url"]
318322
run_url = response["runs"][0]["url"]
319323
return match_url, run_url

scanpipe/tests/pipes/test_matchcode.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,15 @@ def mock_request_post_return(url, files, timeout):
8686
self.assertEqual(expected_match_url, match_url)
8787
self.assertEqual(expected_run_url, run_url)
8888

89+
@mock.patch("scanpipe.pipes.matchcode.request_post")
90+
def test_scanpipe_pipes_matchcode_send_project_json_to_matchcode_failed_request(
91+
self, mock_request_post
92+
):
93+
mock_request_post.return_value = None
94+
with self.assertRaises(matchcode.MatchCodeIOException) as context:
95+
matchcode.send_project_json_to_matchcode(self.project1)
96+
self.assertEqual("Invalid response from MatchCode.io", str(context.exception))
97+
8998
@mock.patch("scanpipe.pipes.matchcode.request_get")
9099
@mock.patch("scanpipe.pipes.matchcode.is_available")
91100
def test_scanpipe_pipes_matchcode_get_run_url_status(
@@ -168,7 +177,7 @@ def test_scanpipe_pipes_matchcode_poll_run_url_status(
168177
"log": "failure message",
169178
},
170179
]
171-
with self.assertRaises(Exception) as context:
180+
with self.assertRaises(matchcode.MatchCodeIOException) as context:
172181
matchcode.poll_run_url_status(run_url, sleep=0)
173182
self.assertTrue("failure message" in str(context.exception))
174183

@@ -197,7 +206,7 @@ def test_scanpipe_pipes_matchcode_poll_run_url_status(
197206
"log": "stop message",
198207
},
199208
]
200-
with self.assertRaises(Exception) as context:
209+
with self.assertRaises(matchcode.MatchCodeIOException) as context:
201210
matchcode.poll_run_url_status(run_url, sleep=0)
202211
self.assertTrue("stop message" in str(context.exception))
203212

@@ -226,7 +235,7 @@ def test_scanpipe_pipes_matchcode_poll_run_url_status(
226235
"log": "stale message",
227236
},
228237
]
229-
with self.assertRaises(Exception) as context:
238+
with self.assertRaises(matchcode.MatchCodeIOException) as context:
230239
matchcode.poll_run_url_status(run_url, sleep=0)
231240
self.assertTrue("stale message" in str(context.exception))
232241

0 commit comments

Comments
 (0)