Merge pull request #54 from adv3nt3/fix/narrow-exception-handling
fix: narrow bare except Exception to specific types where safe
This commit is contained in:
@@ -305,7 +305,7 @@ def mine_convos(
|
||||
# Normalize format
|
||||
try:
|
||||
content = normalize(str(filepath))
|
||||
except Exception:
|
||||
except (OSError, ValueError):
|
||||
continue
|
||||
|
||||
if not content or len(content.strip()) < MIN_CHUNK_SIZE:
|
||||
|
||||
@@ -660,7 +660,7 @@ def detect_entities(file_paths: list, max_files: int = 10) -> dict:
|
||||
all_text.append(content)
|
||||
all_lines.extend(content.splitlines())
|
||||
files_read += 1
|
||||
except Exception:
|
||||
except OSError:
|
||||
continue
|
||||
|
||||
combined_text = "\n".join(all_text)
|
||||
|
||||
@@ -253,7 +253,7 @@ def _wikipedia_lookup(word: str) -> dict:
|
||||
"note": "not found in Wikipedia — likely a proper noun or unusual name",
|
||||
}
|
||||
return {"inferred_type": "unknown", "confidence": 0.0, "wiki_summary": None}
|
||||
except Exception:
|
||||
except (urllib.error.URLError, OSError, json.JSONDecodeError, KeyError):
|
||||
return {"inferred_type": "unknown", "confidence": 0.0, "wiki_summary": None}
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -460,7 +460,7 @@ def process_file(
|
||||
|
||||
try:
|
||||
content = filepath.read_text(encoding="utf-8", errors="replace")
|
||||
except Exception:
|
||||
except OSError:
|
||||
return 0
|
||||
|
||||
content = content.strip()
|
||||
|
||||
@@ -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():
|
||||
@@ -235,7 +235,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