fix(ai): magic.from_file() raises MagicException, only OSError is caught — can crash dir loop #81
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
Two call sites wrap
magic.from_file()intry/except OSErrorbutmagic.MagicException(thepython-magiclibrary's error type) is not anOSErrorsubclass. On any libmagic failure the exception propagates and crashes the dir loop — violating "Graceful degradation everywhere" (CLAUDE.md).Site 1 —
_build_dir_context(runs on every directory before the loop starts)luminos_lib/ai.py:897-916:Site 2 —
_tool_list_directory(dir-loop tool)luminos_lib/ai.py:229-257— same pattern.Repro
Sufficient to trigger on some systems: a file that libmagic can't classify (corrupted, permission-exotic, or a version mismatch between the libmagic binary and the grammar db). Also triggers if libmagic is missing on the host despite
python-magicbeing installed.Fix
Broaden the inner
except OSError:toexcept Exception:at both sites, or wrap themagic.from_file()call in its own narrow try and degrade to an empty MIME string on any failure. A file listing without MIME is a degraded-but-correct result; crashing the whole dir investigation is not.Acceptance
_build_dir_contextsurvives a file thatmagic.from_file()can't classify_tool_list_directorysurvives the same case[mime]suffix, not "(stat failed)"