-
Notifications
You must be signed in to change notification settings - Fork 730
Add error handling for index file loading in SearchIndex #948
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds error handling for decompression and unpickling operations when loading index files in the SearchIndex. The changes ensure that if an error occurs during the loading process, an error message is logged so that the offending file can be identified.
- Wrapped the deserialization of index files with a try/except block.
- Added logging to report errors during index file handling.
paperqa/agents/search.py
Outdated
except Exception: | ||
logger.exception(f"Failed to load index file {file_index_path}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Catching all exceptions may obscure underlying issues; consider catching specific exceptions, such as zlib.error or pickle.UnpicklingError, to handle known error scenarios more accurately.
except Exception: | |
logger.exception(f"Failed to load index file {file_index_path}") | |
except (pickle.UnpicklingError, zlib.error) as e: | |
logger.exception(f"Failed to load index file {file_index_path}: {e}") |
Copilot uses AI. Check for mistakes.
paperqa/agents/search.py
Outdated
zlib.decompress(content) | ||
) | ||
except Exception: | ||
logger.exception(f"Failed to load index file {file_index_path}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After logging the exception when loading the index file fails, _index_files is not reset, potentially returning stale data. Consider assigning a safe fallback value (e.g., an empty dict) to _index_files in the exception block.
logger.exception(f"Failed to load index file {file_index_path}") | |
logger.exception(f"Failed to load index file {file_index_path}") | |
self._index_files = {} |
Copilot uses AI. Check for mistakes.
Co-authored-by: James Braza <jamesbraza@gmail.com>
Thank you for this! |
I got the following error while playing with paper-qa:
Since it was a bit hard to locate the offending file, I added logging so that one can see where the error is.
(Not sure why the error occurred in the first place, it disappeared after deleting the index files.)