Skip to content

Commit ceb31d0

Browse files
author
Cloud
committed
fix: add graceful fallback when ColorBrewer palette loading fails offline
Wrap the urllib.request.urlopen() call in _load_colorbrewer() with try/except to handle network failures gracefully. When offline or the remote gist is unreachable, PyMOL will now print a warning and continue startup normally instead of crashing with an unhandled exception. Changes: - Add try/except around the HTTP request in _load_colorbrewer() - Add timeout=5 to prevent long hangs on slow/unreachable networks - Print a descriptive warning message on failure and return early
1 parent 742d0bd commit ceb31d0

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

configs/.pymolrc.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,11 @@ def should_check() -> bool:
7979
def _load_colorbrewer():
8080
"""Load ColorBrewer palettes into PyMOL."""
8181
url = "https://gist.githubusercontent.com/frankrowe/9007567/raw/colorbrewer.js"
82-
js_text = urllib.request.urlopen(url).read().decode("utf-8")
82+
try:
83+
js_text = urllib.request.urlopen(url, timeout=5).read().decode("utf-8")
84+
except Exception as exc:
85+
print(f"Warning: unable to load ColorBrewer palettes ({exc}). Skipping.")
86+
return
8387

8488
# Extract the JavaScript object containing the ColorBrewer palettes
8589
obj_text = re.search(r"var\s+colorbrewer\s*=\s*(\{.*\});", js_text, flags=re.DOTALL).group(1)

0 commit comments

Comments
 (0)