From 0424e4b00ac0812f69d13d8c03ea822c92f93ded Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Tue, 29 Oct 2024 15:09:22 -0700 Subject: [PATCH] refactor: improve SQLite error handling and logging in tags cache --- aider/repomap.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/aider/repomap.py b/aider/repomap.py index dd99d43de..12bd40b75 100644 --- a/aider/repomap.py +++ b/aider/repomap.py @@ -169,6 +169,10 @@ class RepoMap: def tags_cache_error(self, original_error=None): """Handle SQLite errors by trying to recreate cache, falling back to dict if needed""" + + if self.verbose and original_error: + self.io.tool_warning(f"Tags cache error: {str(original_error)}") + if isinstance(getattr(self, "TAGS_CACHE", None), dict): return @@ -199,8 +203,6 @@ class RepoMap: f"Unable to use tags cache at {path}, falling back to memory cache" ) if self.verbose: - if original_error: - self.io.tool_warning(f"Original error: {str(original_error)}") self.io.tool_warning(f"Cache recreation error: {str(e)}") self.TAGS_CACHE = dict() @@ -237,8 +239,8 @@ class RepoMap: if val is not None and val.get("mtime") == file_mtime: try: return self.TAGS_CACHE[cache_key]["data"] - except SQLITE_ERRORS: - self.tags_cache_error() + except SQLITE_ERRORS as e: + self.tags_cache_error(e) return self.TAGS_CACHE[cache_key]["data"] # miss! @@ -248,8 +250,8 @@ class RepoMap: try: self.TAGS_CACHE[cache_key] = {"mtime": file_mtime, "data": data} self.save_tags_cache() - except SQLITE_ERRORS: - self.tags_cache_error() + except SQLITE_ERRORS as e: + self.tags_cache_error(e) self.TAGS_CACHE[cache_key] = {"mtime": file_mtime, "data": data} return data @@ -352,8 +354,8 @@ class RepoMap: try: cache_size = len(self.TAGS_CACHE) - except SQLITE_ERRORS: - self.tags_cache_error() + except SQLITE_ERRORS as e: + self.tags_cache_error(e) cache_size = len(self.TAGS_CACHE) if len(fnames) - cache_size > 100: