Bare except Exception handlers silently swallow errors in keyword_extractor.py #4

Closed
opened 2026-03-19 17:29:52 +00:00 by llabeyrie · 0 comments
Owner

Description

keyword_extractor.py lines 202 and 211 use bare except Exception handlers that silently return empty results:

try:
    import yake
except Exception:       # line 202 — catches ALL exceptions
    return {}

try:
    extractor = yake.KeywordExtractor(...)
except Exception:       # line 211 — catches ALL exceptions
    return {}

Problems

  • Catches KeyboardInterrupt, MemoryError, SystemExit and other critical exceptions
  • Silently returns {} with no logging — impossible to debug
  • A legitimate YAKE misconfiguration (wrong params, version incompatibility) would be invisible

Fix

try:
    import yake
except ImportError:
    logger.warning("yake not installed, skipping relevance scoring")
    return {}

try:
    extractor = yake.KeywordExtractor(...)
except (ValueError, TypeError) as e:
    logger.warning("YAKE extraction failed: %s", e)
    return {}
## Description `keyword_extractor.py` lines 202 and 211 use bare `except Exception` handlers that silently return empty results: ```python try: import yake except Exception: # line 202 — catches ALL exceptions return {} try: extractor = yake.KeywordExtractor(...) except Exception: # line 211 — catches ALL exceptions return {} ``` ### Problems - Catches `KeyboardInterrupt`, `MemoryError`, `SystemExit` and other critical exceptions - Silently returns `{}` with no logging — impossible to debug - A legitimate YAKE misconfiguration (wrong params, version incompatibility) would be invisible ### Fix ```python try: import yake except ImportError: logger.warning("yake not installed, skipping relevance scoring") return {} try: extractor = yake.KeywordExtractor(...) except (ValueError, TypeError) as e: logger.warning("YAKE extraction failed: %s", e) return {} ```
llabeyrie added the bugpriority: high labels 2026-03-19 17:31:39 +00:00
Sign in to join this conversation.