Skip to content

Commit caa484f

Browse files
committed
error handling
1 parent 8cc78a2 commit caa484f

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

chipflow_lib/steps/silicon.py

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import logging
77
import os
88
import requests
9+
import requests.exceptions
910
import subprocess
1011
import time
1112

@@ -206,21 +207,27 @@ def submit(self, rtlil_path, *, dry_run=False, wait=False):
206207
exit(1)
207208

208209
# Attempt to stream logs
209-
with requests.get(
210-
log_stream_url,
211-
auth=(os.environ["CHIPFLOW_API_KEY_ID"], os.environ["CHIPFLOW_API_KEY_SECRET"]),
212-
stream=True
213-
) as log_resp:
214-
if log_resp.status_code == 200:
215-
for line in log_resp.iter_lines():
216-
if line:
217-
print(line.decode("utf-8")) # Print logs in real-time
218-
elif log_resp.status_code == 404:
219-
logger.error("Log streaming endpoint returned 404: Not Found.")
220-
print("Log streaming failed: Build not found.")
221-
exit(1) # Exit with failure
222-
else:
223-
logger.warning(f"Failed to stream logs: {log_resp.text}")
210+
try:
211+
with requests.get(
212+
log_stream_url,
213+
auth=(os.environ["CHIPFLOW_API_KEY_ID"], os.environ["CHIPFLOW_API_KEY_SECRET"]),
214+
stream=True
215+
) as log_resp:
216+
if log_resp.status_code == 200:
217+
for line in log_resp.iter_lines():
218+
if line:
219+
print(line.decode("utf-8")) # Print logs in real-time
220+
elif log_resp.status_code == 404:
221+
logger.error("Log streaming endpoint returned 404: Not Found.")
222+
print("Log streaming failed: Build not found.")
223+
exit(1) # Exit with failure
224+
else:
225+
logger.warning(f"Failed to stream logs: {log_resp.text}")
226+
except requests.exceptions.ChunkedEncodingError as e:
227+
logger.error("Log streaming failed due to a premature response termination.")
228+
logger.error(f"Error details: {e}")
229+
print("Log streaming interrupted. Please check the build status manually.")
230+
exit(1) # Exit with failure
224231
# Wait before polling again
225232
time.sleep(10)
226233
else:

0 commit comments

Comments
 (0)