1e323cae7d
Site 5 (BC at L290): _async_search_mcp (nested in _search_mcp) had:
try:
data = json.loads(res_str)
if isinstance(data, list): return data
elif isinstance(data, dict) and 'results' in data: return data['results']
return []
except:
return []
Body: bare 'except:' + return [] = empty default = SS-style violation.
Migrated to Result[T] via new module-level helper _parse_search_response_result:
- Returns Result(data=parsed_list) on success
- Returns Result(data=None, errors=[ErrorInfo]) on JSON parse failure
- Handles the list/dict/no-results branch logic
The helper is module-level (does not use self) and is placed BEFORE
class RAGEngine to avoid breaking the class definition (a def at column 0
inside a class ends the class prematurely).
Legacy _async_search_mcp delegates to the helper; on Result errors,
returns [] (preserving the original behavior).
Audit: rag_engine BC 1 -> 0; migration-target: 0.
Remaining 4 INTERNAL_RETHROW sites are Pattern 1/3 of the styleguide
(known audit limitation).
25 lines
884 B
Python
25 lines
884 B
Python
"""Phase 13 site 5: _async_search_mcp Result migration.
|
|
|
|
Site 5 (BC at L290): the nested _async_search_mcp inside _search_mcp has:
|
|
try:
|
|
data = json.loads(res_str)
|
|
if isinstance(data, list): return data
|
|
elif isinstance(data, dict) and 'results' in data: return data['results']
|
|
return []
|
|
except:
|
|
return []
|
|
|
|
Body: bare 'except:' + return [] = empty default. MIGRATE to Result.
|
|
"""
|
|
import sys
|
|
sys.path.insert(0, ".")
|
|
|
|
|
|
def test_phase13_site5_async_search_mcp_no_bare_except():
|
|
import inspect
|
|
import src.rag_engine
|
|
src_text = inspect.getsource(src.rag_engine.RAGEngine._search_mcp)
|
|
assert "except:" not in src_text or "except (ValueError, TypeError)" in src_text, \
|
|
"_search_mcp must not have bare 'except:'"
|
|
assert "except Exception" not in src_text, \
|
|
"_search_mcp must not have bare 'except Exception'" |