Skip to content

Conversation

@smsharma
Copy link
Collaborator

Critical Issue

Bare except: clauses catch ALL exceptions, including:

  • KeyboardInterrupt (user pressing Ctrl+C)
  • SystemExit (program exit)
  • NameError, AttributeError (programming bugs)

This is dangerous because it silently masks bugs. For example, the typo mu_media_vec instead of mu_median_vec in reactions.py:147 was being silently swallowed by the bare except: at line 152 — the code appeared to work but GPU placement was silently failing.

Fix

Changed all bare except: to except (RuntimeError, IndexError): which are the specific exceptions expected when:

  • RuntimeError: No GPU backend available (e.g., JAX not compiled with CUDA support)
  • IndexError: GPU backend exists but no GPU devices found (empty device list)

Files Changed

File Line Change
linx/thermo.py 674 except:except (RuntimeError, IndexError):
linx/weak_rates.py 105 except:except (RuntimeError, IndexError):
linx/weak_rates.py 122 except:except (RuntimeError, IndexError):
linx/reactions.py 152 except:except (RuntimeError, IndexError):

Test plan

  • Run existing tests: pytest pytest/
  • Verify behavior on CPU-only system
  • Verify behavior on GPU system

🤖 Generated with Claude Code

Bare `except:` clauses catch ALL exceptions including KeyboardInterrupt,
SystemExit, and programming errors like NameError or AttributeError.
This can mask bugs silently.

Changed all bare `except:` to `except (RuntimeError, IndexError):` in:
- linx/thermo.py:674
- linx/weak_rates.py:105 and :122
- linx/reactions.py:152

These exceptions are the ones actually expected when GPU is unavailable
(RuntimeError for no GPU backend, IndexError for empty device list).

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@smsharma smsharma requested a review from cgiovanetti January 24, 2026 02:32
Copy link
Owner

@cgiovanetti cgiovanetti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@cgiovanetti cgiovanetti merged commit 215641d into main Jan 26, 2026
1 check passed
@cgiovanetti cgiovanetti deleted the siddharth/fix-bare-except branch January 26, 2026 19:40
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