Filesystem grep reports failed file reads as files without matches
Filesystem grep reports failed file reads as files without matches
Bug Description
The filesystem grep path reads each candidate file and matches the pattern locally. _grep_single_file (openviking/storage/viking_fs/_grep.py) wraps that read in except Exception, logs at debug level, and returns ([], 1):
except Exception as e:
logger.debug(f"Failed to grep {entry_uri}: {e}")
return [], 1
A failed read is not a file without matches. When the storage layer, the encryption layer, or a decoder raises, the file silently disappears from the result set: files_scanned still counts it, the response still reports a complete scan, and callers cannot distinguish "no occurrence in this file" from "this file could not be read". Because the log is at debug, the failure is invisible in normal deployments.
The listing stage already follows the opposite rule: _collect_grep_files skips a PermissionDeniedError only on the first page of a subtree and propagates once traversal has consumed a page, with a comment that swallowing it would "misreport a partial result as complete".
Steps to Reproduce
- Have two files under
viking://resources, one containing the pattern. - Make
VikingFS.readraiseOSError(or any transient storage error) for the other file. - Run
grep("viking://resources", "pattern").
Expected Behavior
The storage failure surfaces to the caller (after logging at warning level). Files that legitimately disappear or lose visibility between listing and reading (NotFoundError, PermissionDeniedError) are still skipped.
Actual Behavior
The unreadable file is reported as having no matches and the response looks like a complete scan.
Environment
- OS: Windows 11
- OpenViking version/commit: main @
37a74437
Additional Context
Fix submitted as PR #7567: _grep_single_file skips only NotFoundError/PermissionDeniedError and re-raises every other failure after a warning log. The regression test fails on unmodified main and passes with the fix; a second test pins the not-found skip behavior.