35bac5eda7
aggregate.py (1 site): - compute_file_stats returns Result[dict[str, int]]. The 2 SILENT_SWALLOW sites (ast.parse + open) now append to errors list. Callers in gui_2.py updated to extract result.data from the cache. api_hooks.py (1 site): - WebSocketServer._handler - was 2 except ...: pass (JSONDecodeError + ConnectionClosed). Now logs warnings instead of silently swallowing. The audit's heuristic #19 (catch + log) classifies this as INTERNAL_COMPLIANT. context_presets.py (1 site): - ContextPresetManager.load_all returns Result[Dict[str, ContextPreset]]. Caller in app_controller.py (load_context_preset) updated to check result.ok. external_editor.py (1 site): - _find_vscode_in_registry returns Result[Optional[str]]. The 1 SILENT_SWALLOW site (subprocess.run) now appends to errors. Caller in ExternalEditorLauncher._resolve_vscode updated to extract result.data. Tests updated to check result.ok and use result.data.
32 lines
1.4 KiB
Python
32 lines
1.4 KiB
Python
from typing import Dict, Any
|
|
|
|
from src.models import ContextPreset
|
|
from src.result_types import Result, ErrorInfo, ErrorKind
|
|
|
|
|
|
class ContextPresetManager:
|
|
"""Manages context presets within the project dictionary (manual_slop.toml)."""
|
|
|
|
def load_all(self, project_dict: Dict[str, Any]) -> Result[Dict[str, ContextPreset]]:
|
|
"""Loads all context presets from the project dictionary."""
|
|
presets: Dict[str, ContextPreset] = {}
|
|
errors: list[ErrorInfo] = []
|
|
presets_data = project_dict.get("context_presets", {})
|
|
for name, data in presets_data.items():
|
|
try:
|
|
presets[name] = ContextPreset.from_dict(name, data)
|
|
except (ValueError, KeyError, TypeError) as e:
|
|
errors.append(ErrorInfo(kind=ErrorKind.INTERNAL, message=str(e), source=f"context_presets.load_all[{name}]", original=e))
|
|
return Result(data=presets, errors=errors)
|
|
|
|
def save_preset(self, project_dict: Dict[str, Any], preset: ContextPreset) -> None:
|
|
"""Saves a context preset into the project dictionary."""
|
|
if "context_presets" not in project_dict:
|
|
project_dict["context_presets"] = {}
|
|
project_dict["context_presets"][preset.name] = preset.to_dict()
|
|
|
|
def delete_preset(self, project_dict: Dict[str, Any], name: str) -> None:
|
|
"""Deletes a context preset from the project dictionary."""
|
|
if "context_presets" in project_dict and name in project_dict["context_presets"]:
|
|
del project_dict["context_presets"][name]
|