File tree Expand file tree Collapse file tree 1 file changed +18
-5
lines changed Expand file tree Collapse file tree 1 file changed +18
-5
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,18 @@ class _Model(Generic[T]):
2828 path : Path
2929
3030
31+ class ModelNotFoundError (Exception ):
32+ """Exception raised when a model is not found."""
33+
34+ def __init__ (self , key : str ) -> None :
35+ """Initialize the exception with the specified model key.
36+
37+ Args:
38+ key: The key of the model that was not found.
39+ """
40+ super ().__init__ (f"Model with key '{ key } ' is not found." )
41+
42+
3143class ModelManager (BackgroundService , Generic [T ]):
3244 """Load, update, monitor and retrieve machine learning models."""
3345
@@ -59,12 +71,13 @@ def _load(path: Path) -> T:
5971 T: The loaded model data.
6072
6173 Raises:
62- FileNotFoundError : If the model file does not exist.
74+ ModelNotFoundError : If the model file does not exist.
6375 """
64- if not path .exists ():
65- raise FileNotFoundError (f"The model path { path } does not exist." )
66- with path .open ("rb" ) as file :
67- return cast (T , pickle .load (file ))
76+ try :
77+ with path .open ("rb" ) as file :
78+ return cast (T , pickle .load (file ))
79+ except FileNotFoundError as exc :
80+ raise ModelNotFoundError (str (path )) from exc
6881
6982 @override
7083 def start (self ) -> None :
You can’t perform that action at this time.
0 commit comments