mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-30 03:56:23 -05:00 
			
		
		
		
	better exception handling
This commit is contained in:
		| @@ -13,6 +13,10 @@ class IncompatibleClassifierVersionError(Exception): | ||||
|     pass | ||||
|  | ||||
|  | ||||
| class ClassifierModelCorruptError(Exception): | ||||
|     pass | ||||
|  | ||||
|  | ||||
| logger = logging.getLogger("paperless.classifier") | ||||
|  | ||||
|  | ||||
| @@ -34,9 +38,8 @@ def load_classifier(): | ||||
|     try: | ||||
|         classifier.load() | ||||
|  | ||||
|     except (EOFError, | ||||
|             IncompatibleClassifierVersionError, | ||||
|             pickle.UnpicklingError): | ||||
|     except (ClassifierModelCorruptError, | ||||
|             IncompatibleClassifierVersionError): | ||||
|         # there's something wrong with the model file. | ||||
|         logger.exception( | ||||
|             f"Unrecoverable error while loading document " | ||||
| @@ -46,7 +49,12 @@ def load_classifier(): | ||||
|         classifier = None | ||||
|     except OSError: | ||||
|         logger.exception( | ||||
|             f"Error while loading document classification model" | ||||
|             f"IO error while loading document classification model" | ||||
|         ) | ||||
|         classifier = None | ||||
|     except Exception: | ||||
|         logger.exception( | ||||
|             f"Unknown error while loading document classification model" | ||||
|         ) | ||||
|         classifier = None | ||||
|  | ||||
| @@ -76,6 +84,7 @@ class DocumentClassifier(object): | ||||
|                 raise IncompatibleClassifierVersionError( | ||||
|                     "Cannor load classifier, incompatible versions.") | ||||
|             else: | ||||
|                 try: | ||||
|                     self.data_hash = pickle.load(f) | ||||
|                     self.data_vectorizer = pickle.load(f) | ||||
|                     self.tags_binarizer = pickle.load(f) | ||||
| @@ -83,6 +92,8 @@ class DocumentClassifier(object): | ||||
|                     self.tags_classifier = pickle.load(f) | ||||
|                     self.correspondent_classifier = pickle.load(f) | ||||
|                     self.document_type_classifier = pickle.load(f) | ||||
|                 except Exception: | ||||
|                     raise ClassifierModelCorruptError() | ||||
|  | ||||
|     def save(self): | ||||
|         with open(settings.MODEL_FILE, "wb") as f: | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 jonaswinkler
					jonaswinkler