Skip to content

Commit

Permalink
[UX] Show log after failure and fix the color issue with narrow window (
Browse files Browse the repository at this point in the history
#4084)

* fix narrow window and show log path during exception

* format

* format
  • Loading branch information
Michaelvll authored Oct 14, 2024
1 parent a0243e5 commit 9243113
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 12 deletions.
6 changes: 3 additions & 3 deletions sky/backends/cloud_vm_ray_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -2844,9 +2844,9 @@ def _provision(
time.sleep(gap_seconds)
continue
logger.error(
f'{colorama.Fore.RED}{colorama.Style.RESET_ALL} '
'Failed to provision resources. '
f'{ux_utils.log_path_hint(log_path)}')
ux_utils.error_message(
'Failed to provision resources. '
f'{ux_utils.log_path_hint(log_path)}'))
error_message += (
'\nTo keep retrying until the cluster is up, use '
'the `--retry-until-up` flag.')
Expand Down
5 changes: 4 additions & 1 deletion sky/provision/provisioner.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,10 @@ def post_provision_runtime_setup(
provision_record=provision_record,
custom_resource=custom_resource)
except Exception: # pylint: disable=broad-except
logger.error('*** Failed setting up cluster. ***')
logger.error(
ux_utils.error_message(
'Failed to set up SkyPilot runtime on cluster.',
provision_logging.config.log_path))
logger.debug(f'Stacktrace:\n{traceback.format_exc()}')
with ux_utils.print_exception_no_traceback():
raise
40 changes: 32 additions & 8 deletions sky/utils/ux_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,6 @@ def run(self, *args, **kwargs):
raise


def starting_message(message: str) -> str:
"""Gets the starting message for the given message."""
return f'⚙︎ {message}'


def log_path_hint(log_path: Union[str, 'pathlib.Path']) -> str:
"""Gets the log path hint for the given log path."""
log_path = str(log_path)
Expand All @@ -135,21 +130,50 @@ def log_path_hint(log_path: Union[str, 'pathlib.Path']) -> str:
return _LOG_PATH_HINT.format(log_path=log_path)


def starting_message(message: str) -> str:
"""Gets the starting message for the given message."""
# We have to reset the color before the message, because sometimes if a
# previous spinner with dimmed color overflows in a narrow terminal, the
# color might be messed up.
return f'{colorama.Style.RESET_ALL}⚙︎ {message}'


def finishing_message(
message: str,
log_path: Optional[Union[str, 'pathlib.Path']] = None) -> str:
"""Gets the finishing message for the given message."""
success_prefix = (f'{colorama.Fore.GREEN}{message}'
f'{colorama.Style.RESET_ALL}')
# We have to reset the color before the message, because sometimes if a
# previous spinner with dimmed color overflows in a narrow terminal, the
# color might be messed up.
success_prefix = (f'{colorama.Style.RESET_ALL}{colorama.Fore.GREEN}✓ '
f'{message}{colorama.Style.RESET_ALL}')
if log_path is None:
return success_prefix
path_hint = log_path_hint(log_path)
return f'{success_prefix} {path_hint}'


def error_message(message: str,
log_path: Optional[Union[str, 'pathlib.Path']] = None) -> str:
"""Gets the error message for the given message."""
# We have to reset the color before the message, because sometimes if a
# previous spinner with dimmed color overflows in a narrow terminal, the
# color might be messed up.
error_prefix = (f'{colorama.Style.RESET_ALL}{colorama.Fore.RED}⨯'
f'{colorama.Style.RESET_ALL} {message}')
if log_path is None:
return error_prefix
path_hint = log_path_hint(log_path)
return f'{error_prefix} {path_hint}'


def retry_message(message: str) -> str:
"""Gets the retry message for the given message."""
return f'{colorama.Fore.YELLOW}{colorama.Style.RESET_ALL} {message}'
# We have to reset the color before the message, because sometimes if a
# previous spinner with dimmed color overflows in a narrow terminal, the
# color might be messed up.
return (f'{colorama.Style.RESET_ALL}{colorama.Fore.YELLOW}↺'
f'{colorama.Style.RESET_ALL} {message}')


def spinner_message(
Expand Down

0 comments on commit 9243113

Please sign in to comment.