[cli] improve error handling, don't swallow errors (#10370)

This commit is contained in:
Richard Liaw
2020-08-27 17:59:44 -07:00
committed by GitHub
parent ed5de89470
commit 922bf9f45a
2 changed files with 14 additions and 10 deletions
+12 -7
View File
@@ -16,8 +16,8 @@ from ray.autoscaler.docker import check_docker_running_cmd, \
with_docker_exec
from ray.autoscaler.log_timer import LogTimer
from ray.autoscaler.subprocess_output_util import (run_cmd_redirected,
ProcessRunnerError)
from ray.autoscaler.subprocess_output_util import (
run_cmd_redirected, ProcessRunnerError, is_output_redirected)
from ray.autoscaler.cli_logger import cli_logger
import colorful as cf
@@ -434,6 +434,11 @@ class SSHCommandRunner(CommandRunnerInterface):
exit_on_fail (bool):
If `exit_on_fail` is `True`, the process will exit
if the command fails (exits with a code other than 0).
Raises:
ProcessRunnerError if using new log style and disabled
login shells.
click.ClickException if using login shells.
"""
try:
# For now, if the output is needed we just skip the new logic.
@@ -459,12 +464,12 @@ class SSHCommandRunner(CommandRunnerInterface):
if exit_on_fail:
raise click.ClickException(
"Command failed: \n\n {}\n".format(quoted_cmd)) \
from None
"Command failed:\n\n {}\n".format(quoted_cmd)) from None
else:
raise click.ClickException(
"SSH command Failed. See above for the output from the"
" failure.") from None
fail_msg = "SSH command failed."
if is_output_redirected():
fail_msg += " See above for the output from the failure."
raise click.ClickException(fail_msg) from None
def run(
self,
@@ -223,7 +223,6 @@ def _run_and_process_output(cmd,
The code is thus 100% thread-safe as long as the stream readers
are read-only except for return values and possible exceptions.
"""
stdin_overwrite = subprocess.PIPE
# This already should be validated in a higher place of the stack.
assert not (does_allow_interactive() and is_output_redirected()), (
@@ -235,9 +234,9 @@ def _run_and_process_output(cmd,
if use_login_shells:
if stdout_file is None:
stdout_file = subprocess.DEVNULL
stdout_file = sys.stdout
if stderr_file is None:
stderr_file = subprocess.DEVNULL
stderr_file = sys.stderr
return subprocess.check_call(
cmd,
# See implementation note #2