Skip to content

Commit f7be600

Browse files
committed
fix(openqa-list-incidents): replace asserts with error handling
Motivation: Using 'assert' for runtime validation is discouraged as they can be optimized away and provide poor error messages to the user. Design Choices: - Replaced 'assert' calls in 'get_api_url' with explicit checks that call 'sys.exit' with descriptive error messages. Benefits: More robust error handling and improved user feedback when unexpected API results occur.
1 parent 8ca8bf3 commit f7be600

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

openqa-list-incidents

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,13 +213,15 @@ def get_api_url(job: str) -> str:
213213
data = got.json()
214214
except RequestException as error:
215215
sys.exit(f"ERROR: {job}: {error}")
216-
assert len(data) == 1
216+
if len(data) != 1:
217+
sys.exit(f"ERROR: {job}: expected 1 job, got {len(data)}")
217218
job = str(data[0]["id"])
218219
else:
219220
# Support both "/t1234" & "/tests/1234"
220221
job = pathlib.Path(url.path).name.removeprefix("t")
221222

222-
assert job.isdigit()
223+
if not job.isdigit():
224+
sys.exit(f"ERROR: {job}: invalid job ID")
223225
return f"https://{url.netloc}/api/v1/jobs/{job}"
224226

225227

0 commit comments

Comments
 (0)