mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-10 13:02:59 +00:00
fix: narrow bare except blocks to specific exception types (#282)
Replace 6 bare `except:` blocks with targeted exception types: - logo_downloader.py: OSError for file removal, (OSError, IOError) for font loading - layout_manager.py: (ValueError, TypeError, KeyError, IndexError) for format string - app.py: (OSError, ValueError) for CPU temp, (SubprocessError, OSError) for systemctl, (KeyError, TypeError, ValueError) for config parsing Co-authored-by: 5ymb01 <5ymb01@users.noreply.github.com> Co-authored-by: 5ymb01 <noreply@github.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -238,7 +238,7 @@ class LayoutManager:
|
||||
# Format the text
|
||||
try:
|
||||
text = format_str.format(value=value)
|
||||
except:
|
||||
except (ValueError, TypeError, KeyError, IndexError):
|
||||
text = str(value)
|
||||
|
||||
self.display_manager.draw_text(text, x, y, color)
|
||||
|
||||
@@ -237,7 +237,7 @@ class LogoDownloader:
|
||||
logger.error(f"Downloaded file for {team_abbreviation} is not a valid image or conversion failed: {e}")
|
||||
try:
|
||||
os.remove(filepath) # Remove invalid file
|
||||
except:
|
||||
except OSError:
|
||||
pass
|
||||
return False
|
||||
|
||||
@@ -642,10 +642,10 @@ class LogoDownloader:
|
||||
# Try to load a font, fallback to default
|
||||
try:
|
||||
font = ImageFont.truetype("assets/fonts/PressStart2P-Regular.ttf", 12)
|
||||
except:
|
||||
except (OSError, IOError):
|
||||
try:
|
||||
font = ImageFont.load_default()
|
||||
except:
|
||||
except (OSError, IOError):
|
||||
font = None
|
||||
|
||||
# Draw team abbreviation
|
||||
|
||||
@@ -442,7 +442,7 @@ def system_status_generator():
|
||||
try:
|
||||
with open('/sys/class/thermal/thermal_zone0/temp', 'r') as f:
|
||||
cpu_temp = round(float(f.read()) / 1000.0, 1)
|
||||
except:
|
||||
except (OSError, ValueError):
|
||||
pass
|
||||
|
||||
except ImportError:
|
||||
@@ -456,7 +456,7 @@ def system_status_generator():
|
||||
result = subprocess.run(['systemctl', 'is-active', 'ledmatrix'],
|
||||
capture_output=True, text=True, timeout=2)
|
||||
service_active = result.stdout.strip() == 'active'
|
||||
except:
|
||||
except (subprocess.SubprocessError, OSError):
|
||||
pass
|
||||
|
||||
status = {
|
||||
@@ -492,7 +492,7 @@ def display_preview_generator():
|
||||
parallel = main_config.get('display', {}).get('hardware', {}).get('parallel', 1)
|
||||
width = cols * chain_length
|
||||
height = rows * parallel
|
||||
except:
|
||||
except (KeyError, TypeError, ValueError):
|
||||
width = 128
|
||||
height = 64
|
||||
|
||||
|
||||
Reference in New Issue
Block a user