Skip to content

Commit 921c3a7

Browse files
committed
parse setup command errors for more precise tracebacks
1 parent f11b530 commit 921c3a7

File tree

3 files changed

+49
-13
lines changed

3 files changed

+49
-13
lines changed

runhouse/resources/hardware/cluster.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
generate_default_name,
4040
install_conda,
4141
locate_working_dir,
42+
parse_traceback_error,
4243
run_command_with_password_login,
4344
run_setup_command,
4445
thread_coroutine,
@@ -1231,9 +1232,14 @@ def _start_or_restart_helper(
12311232
stream_logs=True,
12321233
node=self.head_ip,
12331234
)
1234-
1235-
if not status_codes[0] == 0:
1236-
raise ValueError(f"Failed to restart server {self.name}")
1235+
ret_code = status_codes[0]
1236+
if ret_code != 0:
1237+
raise RuntimeError(
1238+
parse_traceback_error(
1239+
status_codes[1],
1240+
fallback_msg=f"Failed to restart server {self.name}",
1241+
)
1242+
)
12371243

12381244
if https_flag:
12391245
rns_address = self.rns_address or self.name

runhouse/resources/packages/package.py

+28-10
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
install_conda,
2323
is_python_package_string,
2424
locate_working_dir,
25+
parse_traceback_error,
2526
run_setup_command,
2627
)
2728

@@ -281,22 +282,31 @@ def _install(
281282
conda_env_name=conda_env_name, cluster=cluster
282283
)
283284
logger.info(f"Running via install_method pip: {install_cmd}")
284-
retcode = run_setup_command(install_cmd, cluster=cluster, node=node)[0]
285-
if retcode != 0:
285+
status_codes = run_setup_command(install_cmd, cluster=cluster, node=node)
286+
ret_code = status_codes[0]
287+
if ret_code != 0:
286288
raise RuntimeError(
287-
f"Pip install {install_cmd} failed, check that the package exists and is available for your platform."
289+
parse_traceback_error(
290+
status_codes[1],
291+
fallback_msg=f"Pip install {install_cmd} failed, check that the package exists "
292+
f"and is available for your platform.",
293+
)
288294
)
289295

290296
elif self.install_method == "conda":
291297
install_cmd = self._conda_install_cmd(
292298
conda_env_name=conda_env_name, cluster=cluster
293299
)
294300
logger.info(f"Running via install_method conda: {install_cmd}")
295-
retcode = run_setup_command(install_cmd, cluster=cluster, node=node)[0]
296-
if retcode != 0:
301+
status_codes = run_setup_command(install_cmd, cluster=cluster, node=node)
302+
ret_code = status_codes[0]
303+
if ret_code != 0:
297304
raise RuntimeError(
298-
f"Conda install {install_cmd} failed, check that the package exists and is "
299-
"available for your platform."
305+
parse_traceback_error(
306+
status_codes[1],
307+
fallback_msg=f"Conda install {install_cmd} failed, check that the package exists and is "
308+
"available for your platform.",
309+
)
300310
)
301311

302312
elif self.install_method == "reqs":
@@ -305,11 +315,19 @@ def _install(
305315
)
306316
if install_cmd:
307317
logger.info(f"Running via install_method reqs: {install_cmd}")
308-
retcode = run_setup_command(install_cmd, cluster=cluster, node=node)[0]
309-
if retcode != 0:
318+
status_codes = run_setup_command(
319+
install_cmd, cluster=cluster, node=node
320+
)
321+
ret_code = status_codes[0]
322+
if ret_code != 0:
310323
raise RuntimeError(
311-
f"Reqs install {install_cmd} failed, check that the package exists and is available for your platform."
324+
parse_traceback_error(
325+
status_codes[1],
326+
fallback_msg=f"Reqs install {install_cmd} failed, check that the package exists "
327+
f"and is available for your platform.",
328+
)
312329
)
330+
313331
else:
314332
logger.info(
315333
f"{self.install_target.full_local_path_str()}/requirements.txt not found, skipping reqs install"

runhouse/utils.py

+12
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,18 @@ def install_conda(cluster: "Cluster" = None, node: Optional[str] = None):
8686
raise RuntimeError("Could not install Conda.")
8787

8888

89+
def parse_traceback_error(traceback_msg: str, fallback_msg: str):
90+
traceback_match = re.search(
91+
r"Traceback.*?\n(.+Error: .+)", traceback_msg, re.DOTALL
92+
)
93+
if not traceback_match:
94+
return fallback_msg
95+
96+
error_message = traceback_match.group(1).strip()
97+
cleaned_message = re.sub(r"\x1b\[[0-9;]*m", "", error_message)
98+
return cleaned_message
99+
100+
89101
def create_conda_env_on_cluster(
90102
conda_env_name: str,
91103
conda_config: Dict,

0 commit comments

Comments
 (0)