Skip to content

Commit

Permalink
[UX] Friendly error message when mounting fails with non-empty mount …
Browse files Browse the repository at this point in the history
…path (#1908)
  • Loading branch information
landscapepainter authored May 20, 2023
1 parent 804a8bb commit c991c7d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
31 changes: 22 additions & 9 deletions sky/backends/cloud_vm_ray_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -3634,15 +3634,28 @@ def _execute_storage_mounts(self, handle: CloudVmRayResourceHandle,
if storage_obj.source else storage_obj.name)
if isinstance(src_print, list):
src_print = ', '.join(src_print)
backend_utils.parallel_data_transfer_to_nodes(
runners,
source=src_print,
target=dst,
cmd=mount_cmd,
run_rsync=False,
action_message='Mounting',
log_path=log_path,
)
try:
backend_utils.parallel_data_transfer_to_nodes(
runners,
source=src_print,
target=dst,
cmd=mount_cmd,
run_rsync=False,
action_message='Mounting',
log_path=log_path,
)
except exceptions.CommandError as e:
if e.returncode == exceptions.MOUNT_PATH_NON_EMPTY_CODE:
mount_path = (f'{colorama.Fore.RED}'
f'{colorama.Style.BRIGHT}{dst}'
f'{colorama.Style.RESET_ALL}')
error_msg = (f'Mount path {mount_path} is non-empty.'
f' {mount_path} may be a standard unix '
f'path or may contain files from a previous'
f' task. To fix, change the mount path'
f' to an empty or non-existent path.')
raise RuntimeError(error_msg) from None

end = time.time()
logger.debug(f'Storage mount sync took {end - start} seconds.')

Expand Down
6 changes: 4 additions & 2 deletions sky/data/mounting_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import textwrap
from typing import Optional

from sky import exceptions


def get_mounting_command(
mount_path: str,
Expand Down Expand Up @@ -59,8 +61,8 @@ def get_mounting_command(
else
# Check if mount path contains files
if [ "$(ls -A $MOUNT_PATH)" ]; then
echo "Mount path $MOUNT_PATH is not empty. Please make sure its empty."
exit 1
echo "Mount path $MOUNT_PATH is not empty. Please mount to another path or remove it first."
exit {exceptions.MOUNT_PATH_NON_EMPTY_CODE}
fi
fi
echo "Mounting $SOURCE_BUCKET to $MOUNT_PATH with $MOUNT_BINARY..."
Expand Down
2 changes: 2 additions & 0 deletions sky/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
KEYBOARD_INTERRUPT_CODE = 130
SIGTSTP_CODE = 146
RSYNC_FILE_NOT_FOUND_CODE = 23
# Arbitrarily chosen value. Used in SkyPilot's storage mounting scripts
MOUNT_PATH_NON_EMPTY_CODE = 42


class ResourcesUnavailableError(Exception):
Expand Down

0 comments on commit c991c7d

Please sign in to comment.