mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-10-04 06:15:09 +00:00
* fix(core): font zip cache, monotonic timers, resolver back-off, and other core/common fixes - font_manager: a .zip font URL is served as its extracted font after a restart (the cached-file check returned the archive first); downloads use requests with a 30s timeout into a temp file + os.replace. - api_helper / sync_manager: rate-limit and heartbeat/leader timeouts use time.monotonic(); last_request_time and the status file's ts stay wall-clock. set_on_new_cycle docstring no longer claims core uses it. - logo_helper: the placeholder uses the same scaled box as a real logo. - permission_utils: one _sudo_bash_candidates() helper (with the sudoers exact-argv rationale) shared by sudo_remove_directory, which now retries the next bash path on a sudo refusal, and install_requirements_file. - dynamic_team_resolver: failed/empty fetch backs off 5 min; duplicate INFO log and contradictory docstring example fixed. - element_style: scale default looked up through element aliases. - background_data_service: cache-hit callback runs outside the lock. - config_arrays: union-aware type check (["array","null"]); stale dotToNested() reference removed. - auto_update_setup: non-dict auto_update reads as off; temp result file unlinked when the write fails. - exceptions: constructors copy the caller's context dict. - logging_config: StructuredFormatter json.dumps(default=str). - error_aggregator: removed unused export_path/export_to_file/_auto_export. - Docstrings: validate_file_upload max_size_mb, raise_on_errors. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(sync): retry the status-file rename like the other atomic writers On Windows os.replace can fail with "Access is denied" while a scanner briefly holds the target open; config_manager_atomic._replace already retries that (and re-raises at once on other platforms). The sync status writer called os.replace directly, which made test_concurrent_writers_each_use_their_own_temp_file flaky on Windows. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
120 lines
4.0 KiB
Python
120 lines
4.0 KiB
Python
"""
|
|
Custom exception hierarchy for LEDMatrix.
|
|
|
|
Provides specific exception types for different error categories,
|
|
enabling better error handling and debugging.
|
|
"""
|
|
|
|
|
|
class LEDMatrixError(Exception):
|
|
"""Base exception for all LEDMatrix errors."""
|
|
|
|
def __init__(self, message: str, context: dict = None):
|
|
"""
|
|
Initialize the exception.
|
|
|
|
Args:
|
|
message: Error message
|
|
context: Optional context dictionary with additional error details
|
|
"""
|
|
super().__init__(message)
|
|
self.message = message
|
|
self.context = context or {}
|
|
|
|
def __str__(self) -> str:
|
|
"""Return formatted error message with context."""
|
|
if self.context:
|
|
context_str = ", ".join(f"{k}={v}" for k, v in self.context.items())
|
|
return f"{self.message} ({context_str})"
|
|
return self.message
|
|
|
|
|
|
class CacheError(LEDMatrixError):
|
|
"""Exception raised for cache-related errors."""
|
|
|
|
def __init__(self, message: str, cache_key: str = None, context: dict = None):
|
|
"""
|
|
Initialize cache error.
|
|
|
|
Args:
|
|
message: Error message
|
|
cache_key: Optional cache key that caused the error
|
|
context: Optional context dictionary
|
|
"""
|
|
if cache_key:
|
|
# Copy so the caller's dict isn't mutated (a reused context
|
|
# dict would otherwise collect every error's keys).
|
|
context = dict(context or {})
|
|
context['cache_key'] = cache_key
|
|
super().__init__(message, context)
|
|
self.cache_key = cache_key
|
|
|
|
|
|
class ConfigError(LEDMatrixError):
|
|
"""Exception raised for configuration-related errors."""
|
|
|
|
def __init__(self, message: str, config_path: str = None, field: str = None, context: dict = None):
|
|
"""
|
|
Initialize config error.
|
|
|
|
Args:
|
|
message: Error message
|
|
config_path: Optional path to config file
|
|
field: Optional field name that caused the error
|
|
context: Optional context dictionary
|
|
"""
|
|
if config_path or field:
|
|
# Copy so the caller's dict isn't mutated (a reused context
|
|
# dict would otherwise collect every error's keys).
|
|
context = dict(context or {})
|
|
if config_path:
|
|
context['config_path'] = config_path
|
|
if field:
|
|
context['field'] = field
|
|
super().__init__(message, context)
|
|
self.config_path = config_path
|
|
self.field = field
|
|
|
|
|
|
class PluginError(LEDMatrixError):
|
|
"""Exception raised for plugin-related errors."""
|
|
|
|
def __init__(self, message: str, plugin_id: str = None, context: dict = None):
|
|
"""
|
|
Initialize plugin error.
|
|
|
|
Args:
|
|
message: Error message
|
|
plugin_id: Optional plugin ID that caused the error
|
|
context: Optional context dictionary
|
|
"""
|
|
if plugin_id:
|
|
# Copy so the caller's dict isn't mutated (a reused context
|
|
# dict would otherwise collect every error's keys).
|
|
context = dict(context or {})
|
|
context['plugin_id'] = plugin_id
|
|
super().__init__(message, context)
|
|
self.plugin_id = plugin_id
|
|
|
|
|
|
class DisplayError(LEDMatrixError):
|
|
"""Exception raised for display-related errors."""
|
|
|
|
def __init__(self, message: str, display_mode: str = None, context: dict = None):
|
|
"""
|
|
Initialize display error.
|
|
|
|
Args:
|
|
message: Error message
|
|
display_mode: Optional display mode that caused the error
|
|
context: Optional context dictionary
|
|
"""
|
|
if display_mode:
|
|
# Copy so the caller's dict isn't mutated (a reused context
|
|
# dict would otherwise collect every error's keys).
|
|
context = dict(context or {})
|
|
context['display_mode'] = display_mode
|
|
super().__init__(message, context)
|
|
self.display_mode = display_mode
|
|
|