Skip to content

Commit b5e0dab

Browse files
[Catalog] Better handling for catalog fetch failure (skypilot-org#1525)
* Handle catalog download failures * lint * comments * lint
1 parent e9b378e commit b5e0dab

File tree

2 files changed

+37
-10
lines changed

2 files changed

+37
-10
lines changed

sky/clouds/service_catalog/common.py

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,20 +99,35 @@ def _need_update() -> bool:
9999
if pull_frequency_hours is not None:
100100
update_frequency_str = f' (every {pull_frequency_hours} hours)'
101101
with backend_utils.safe_console_status(
102-
f'Updating {cloud} catalog{update_frequency_str}'):
102+
(f'Updating {cloud} catalog: '
103+
f'{filename}'
104+
f'{update_frequency_str}')) as status:
103105
try:
104106
r = requests.get(url)
105107
r.raise_for_status()
106108
except requests.exceptions.RequestException as e:
107-
logger.error(f'Failed to download {cloud} catalog:')
108-
with ux_utils.print_exception_no_traceback():
109-
raise e
110-
# Save the catalog to a local file.
111-
os.makedirs(os.path.dirname(catalog_path), exist_ok=True)
112-
with open(catalog_path, 'w') as f:
113-
f.write(r.text)
114-
with open(meta_path + '.md5', 'w') as f:
115-
f.write(hashlib.md5(r.text.encode()).hexdigest())
109+
ux_utils.console_newline()
110+
status.stop()
111+
error_str = (f'Failed to fetch {cloud} catalog '
112+
f'{filename}. ')
113+
if os.path.exists(catalog_path):
114+
logger.warning(
115+
f'{error_str}Using cached catalog files.')
116+
# Update catalog file modification time.
117+
os.utime(catalog_path, None) # Sets to current time
118+
else:
119+
logger.error(
120+
f'{error_str}Please check your internet connection.'
121+
)
122+
with ux_utils.print_exception_no_traceback():
123+
raise e
124+
else:
125+
# Download successful, save the catalog to a local file.
126+
os.makedirs(os.path.dirname(catalog_path), exist_ok=True)
127+
with open(catalog_path, 'w') as f:
128+
f.write(r.text)
129+
with open(meta_path + '.md5', 'w') as f:
130+
f.write(hashlib.md5(r.text.encode()).hexdigest())
116131

117132
try:
118133
df = pd.read_csv(catalog_path)

sky/utils/ux_utils.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,18 @@
33
import os
44
import sys
55

6+
import rich.console as rich_console
7+
8+
console = rich_console.Console()
9+
10+
11+
def console_newline():
12+
"""Print a newline to the console using rich.
13+
14+
Useful when catching exceptions inside console.status()
15+
"""
16+
console.print()
17+
618

719
@contextlib.contextmanager
820
def print_exception_no_traceback():

0 commit comments

Comments
 (0)