Skip to content

Commit d0a3177

Browse files
committed
refactor: improve CLI refresh error handling and validation
- Add directory type validation to catch incorrect paths early - Improve exception handling with specific exception types - Distinguish between expected and unexpected errors in logging - Better error categorization aids debugging and monitoring
1 parent cfd7651 commit d0a3177

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/tagstudio/core/cli_driver.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ def refresh_library(self, library_path: str) -> int:
3535
logger.error("Library path does not exist", path=path)
3636
return 1
3737

38+
if not path.is_dir():
39+
logger.error("Library path is not a directory", path=path)
40+
return 1
41+
3842
logger.info("Opening library", path=path)
3943
open_status = self.lib.open_library(path)
4044

@@ -84,8 +88,15 @@ def refresh_library(self, library_path: str) -> int:
8488
)
8589
return 0
8690

87-
except Exception as e:
88-
logger.exception("Error during library refresh", error=str(e))
91+
except (OSError, ValueError, RuntimeError) as e:
92+
logger.error(
93+
"Expected error during library refresh",
94+
error_type=type(e).__name__,
95+
error=str(e),
96+
)
97+
return 1
98+
except Exception:
99+
logger.exception("Unexpected error during library refresh")
89100
return 1
90101

91102
finally:

0 commit comments

Comments
 (0)