diff --git a/telescope/utils.py b/telescope/utils.py index 458f987f..103e780f 100644 --- a/telescope/utils.py +++ b/telescope/utils.py @@ -281,7 +281,10 @@ def extract_json(path, data): istep = int(step) except ValueError: raise ValueError(str(ke)) # Original error with step as string - data = data[istep] + try: + data = data[istep] + except IndexError: + raise ValueError(str(ke)) # Original error with step as string return data diff --git a/tests/test_utils.py b/tests/test_utils.py index 138cb15b..38c082a7 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -61,9 +61,17 @@ def test_extract_json(): assert extract_json(".pings.0", data) == 314 assert extract_json(".min_timestamp", data) == "2020-09-24T10:29:44.925" - with pytest.raises(ValueError): + with pytest.raises(ValueError) as exc_info: extract_json(".pings.a", data) + assert str(exc_info.value) == "list indices must be integers or slices, not str" + + with pytest.raises(ValueError) as exc_info: extract_json(".field", "An error returned by check") + assert str(exc_info.value) == "string indices must be integers" + + with pytest.raises(ValueError) as exc_info: + extract_json(".percentiles.75.value", {"percentiles": "No results"}) + assert str(exc_info.value) == "string indices must be integers" async def test_bugzilla_fetch_fallsback_to_empty_list(mock_aioresponses, config):