fix: narrow bare except Exception to specific types where safe
Replace broad except Exception with specific exception types in 6 sites where the expected failure mode is well-defined: - normalize.py: OSError for file read, ImportError for optional import - miner.py: OSError for file read_text - entity_detector.py: OSError for file read in scan loop - convo_miner.py: (OSError, ValueError) for normalize which reads and parses files - entity_registry.py: (URLError, OSError, JSONDecodeError, KeyError) for Wikipedia lookup fallback ChromaDB except Exception sites (~30) are left broad for now. chromadb.errors defines NotFoundError, DuplicateIDError, InvalidDimensionException etc., but narrowing those sites requires importing from chromadb.errors and validating across supported versions (>=0.4.0). MCP server handlers also left broad for resilience.
This commit is contained in:
@@ -27,7 +27,7 @@ def normalize(filepath: str) -> str:
|
||||
try:
|
||||
with open(filepath, "r", encoding="utf-8", errors="replace") as f:
|
||||
content = f.read()
|
||||
except Exception as e:
|
||||
except OSError as e:
|
||||
raise IOError(f"Could not read {filepath}: {e}")
|
||||
|
||||
if not content.strip():
|
||||
@@ -213,7 +213,7 @@ def _messages_to_transcript(messages: list, spellcheck: bool = True) -> str:
|
||||
from mempalace.spellcheck import spellcheck_user_text
|
||||
|
||||
_fix = spellcheck_user_text
|
||||
except Exception:
|
||||
except ImportError:
|
||||
_fix = None
|
||||
else:
|
||||
_fix = None
|
||||
|
||||
Reference in New Issue
Block a user