Skip to content

Commit a2761c2

Browse files
committed
error handling
1 parent b4da826 commit a2761c2

File tree

1 file changed

+16
-23
lines changed

1 file changed

+16
-23
lines changed

chipflow_lib/steps/silicon.py

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import logging
88
import os
99
import requests
10-
import requests.exceptions
1110
import subprocess
1211
import sys
1312
import time
@@ -231,29 +230,23 @@ def submit(self, rtlil_path, *, dry_run=False, wait=False):
231230
print("Build failed.")
232231
exit(1)
233232

234-
# Attempt to stream logs
235-
try:
236-
with requests.get(
237-
log_stream_url,
238-
auth=(os.environ["CHIPFLOW_API_KEY_ID"], os.environ["CHIPFLOW_API_KEY_SECRET"]),
239-
stream=True
240-
) as log_resp:
241-
if log_resp.status_code == 200:
242-
for line in log_resp.iter_lines():
243-
if line:
244-
print(line.decode("utf-8")) # Print logs in real-time
245-
elif log_resp.status_code == 404:
246-
logger.error("Log streaming endpoint returned 404: Not Found.")
247-
print("Log streaming failed: Build not found.")
248-
exit(1) # Exit with failure
249-
else:
250-
logger.warning(f"Failed to stream logs: {log_resp.text}")
251-
except requests.exceptions.ChunkedEncodingError as e:
252-
logger.error("Log streaming failed due to a premature response termination.")
253-
logger.error(f"Error details: {e}")
254-
print("Log streaming interrupted. Please check the build status manually.")
255233
# Wait before polling again
256-
time.sleep(10)
234+
# time.sleep(10)
235+
# Attempt to stream logs rather than time.sleep
236+
with requests.get(
237+
log_stream_url,
238+
auth=(os.environ["CHIPFLOW_API_KEY_ID"], os.environ["CHIPFLOW_API_KEY_SECRET"]),
239+
stream=True
240+
) as log_resp:
241+
if log_resp.status_code == 200:
242+
for line in log_resp.iter_lines():
243+
if line:
244+
print(line.decode("utf-8")) # Print logs in real-time
245+
sys.stdout.flush()
246+
else:
247+
logger.warning(f"Failed to stream logs: {log_resp.text}")
248+
time.sleep(10) # Wait before polling again
249+
257250
else:
258251
# Log detailed information about the failed request
259252
logger.error(f"Request failed with status code {resp.status_code}")

0 commit comments

Comments
 (0)