steam-backlog-enforcer/steam_installer/errors.py
Krzysztof kuhy Rudnicki a76e726e36 Merge steam-game-installer into the repo
The installer ships as the steam_installer package beside
steam_backlog_enforcer, with its tests, docs and Proton lock. The
enforcer's fast install now starts the installer from this checkout.

Both appinfo.vdf readers share one key-value decoder
(steam_installer.appinfo_kv), and the duplicated test fixtures and
helpers are folded into conftest and _cli_helpers so the whole-tree
duplicate-code check is clean. check_requirements_sync treats sibling
packages as first-party.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WzxdWZCxnNWLtpVwFLVk9w
2026-11-22 20:25:39 +01:00

46 lines
1.4 KiB
Python

"""Base class of every error this package raises on purpose, and the crash guard."""
from __future__ import annotations
from typing import TYPE_CHECKING
if TYPE_CHECKING:
import logging
from pathlib import Path
from types import TracebackType
class InstallerError(Exception):
"""A failure the installer reports and exits on, as opposed to a bug."""
class CrashGuard:
"""Context manager: log any ``Exception`` with the run-log path, swallow it.
``try/except Exception`` would say the same, but pylint's broad-exception
check rejects it. ``KeyboardInterrupt`` and other ``BaseException`` pass.
"""
def __init__(self, logger: logging.Logger, log_path: Path) -> None:
"""Remember where a crash is reported."""
self.logger = logger
self.log_path = log_path
def __enter__(self) -> None:
"""Nothing to set up."""
def __exit__(
self,
exc_type: type[BaseException] | None,
exc: BaseException | None,
tb: TracebackType | None,
) -> bool:
"""Report an ``Exception`` and swallow it; let everything else pass."""
if not isinstance(exc, Exception):
return False
self.logger.error(
"Run failed with an unhandled error", exc_info=(exc_type, exc, tb)
)
self.logger.info("Run log (send this): %s", self.log_path)
return True