Skip to content

fix: add graceful fallback when ColorBrewer palette loading fails offline#1

Merged
FridrichMethod merged 1 commit intoFridrichMethod:mainfrom
tom832:fix/colorbrewer-offline-fallback
Mar 27, 2026
Merged

fix: add graceful fallback when ColorBrewer palette loading fails offline#1
FridrichMethod merged 1 commit intoFridrichMethod:mainfrom
tom832:fix/colorbrewer-offline-fallback

Conversation

@tom832
Copy link
Copy Markdown

@tom832 tom832 commented Mar 27, 2026

Problem

_load_colorbrewer() calls urllib.request.urlopen(url) without any error handling. When the network is unavailable (offline, DNS failure, firewall, etc.), this raises an unhandled exception that prevents PyMOL from starting normally.

Solution

  • Wrap the HTTP request in a try/except block
  • Add timeout=5 to avoid long hangs on slow/unreachable networks
  • On failure, print a friendly warning and return early — PyMOL continues startup without ColorBrewer palettes
  • No other code is changed

Changes

-    js_text = urllib.request.urlopen(url).read().decode("utf-8")
+    try:
+        js_text = urllib.request.urlopen(url, timeout=5).read().decode("utf-8")
+    except Exception as exc:
+        print(f"Warning: unable to load ColorBrewer palettes ({exc}). Skipping.")
+        return

…line

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
@FridrichMethod FridrichMethod merged commit 7a6620d into FridrichMethod:main Mar 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants