Skip to content

Replace bare except: with except Exception: across the codebase - #1088

Closed
robcab75 wants to merge 10 commits into
mathoudebine:mainfrom
robcab75:fix/bare-except-clauses
Closed

robcab75 wants to merge 10 commits into
mathoudebine:mainfrom
robcab75:fix/bare-except-clauses

Conversation

@robcab75

@robcab75 robcab75 commented Sep 8, 2026

Copy link
Copy Markdown

Summary

  • Bare except: clauses silently swallow KeyboardInterrupt/SystemExit/GeneratorExit along with real errors, which can make the process hard to interrupt and hides bugs that should surface.
  • Mechanically replaced every bare except: with except Exception: (95 occurrences across sensors_python.py, configure.py, theme-editor.py, library/stats.py, main.py, library/config.py, library/lcd/lcd_comm.py, library/lcd/lcd_comm_rev_c.py, library/pythoncheck.py, library/sensors/sensors_librehardwaremonitor.py), one commit per file for easy review.
  • Behavior for actual sensor/UI errors is unchanged — except Exception: still catches everything these blocks were built to handle.

Test plan

  • python -m pytest tests/ — same pass/fail counts as main (no regressions introduced by this change)
  • python -m py_compile on every touched file
  • flake8 --select=E9,F63,F7,F82 on every touched file — no hard errors

🤖 Generated with Claude Code

https://claude.ai/code/session_01FyR2qGEWt3ApGumu5ykE5X

robcab75 and others added 10 commits September 8, 2026 12:01
Bare `except:` blocks silently swallow KeyboardInterrupt/SystemExit
along with real errors, making the process hard to interrupt and
hiding bugs. Switch all 35 occurrences to `except Exception:`, which
preserves existing behavior for actual sensor errors.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FyR2qGEWt3ApGumu5ykE5X
Same rationale as sensors_python.py: bare except: silently swallows
KeyboardInterrupt/SystemExit along with real errors. Switch all 24
occurrences to except Exception:, preserving existing behavior.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FyR2qGEWt3ApGumu5ykE5X
Same rationale as sensors_python.py/configure.py: bare except: silently
swallows KeyboardInterrupt/SystemExit along with real errors. Switch to
except Exception:, preserving existing behavior.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FyR2qGEWt3ApGumu5ykE5X
Same rationale as sensors_python.py/configure.py: bare except: silently
swallows KeyboardInterrupt/SystemExit along with real errors. Switch to
except Exception:, preserving existing behavior.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FyR2qGEWt3ApGumu5ykE5X
Same rationale as sensors_python.py/configure.py: bare except: silently
swallows KeyboardInterrupt/SystemExit along with real errors. Switch to
except Exception:, preserving existing behavior.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FyR2qGEWt3ApGumu5ykE5X
Same rationale as sensors_python.py/configure.py: bare except: silently
swallows KeyboardInterrupt/SystemExit along with real errors. Switch to
except Exception:, preserving existing behavior.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FyR2qGEWt3ApGumu5ykE5X
Same rationale as sensors_python.py/configure.py: bare except: silently
swallows KeyboardInterrupt/SystemExit along with real errors. Switch to
except Exception:, preserving existing behavior.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FyR2qGEWt3ApGumu5ykE5X
Same rationale as sensors_python.py/configure.py: bare except: silently
swallows KeyboardInterrupt/SystemExit along with real errors. Switch to
except Exception:, preserving existing behavior.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FyR2qGEWt3ApGumu5ykE5X
Same rationale as sensors_python.py/configure.py: bare except: silently
swallows KeyboardInterrupt/SystemExit along with real errors. Switch to
except Exception:, preserving existing behavior.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FyR2qGEWt3ApGumu5ykE5X
…or.py

Same rationale as sensors_python.py/configure.py: bare except: silently
swallows KeyboardInterrupt/SystemExit along with real errors. Switch to
except Exception:, preserving existing behavior.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FyR2qGEWt3ApGumu5ykE5X
@robcab75 robcab75 closed this by deleting the head repository Sep 8, 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.

1 participant