mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-09 09:58:20 -05:00
better exception handling
This commit is contained in:
parent
de08d17835
commit
635c96accf
@ -13,6 +13,10 @@ class IncompatibleClassifierVersionError(Exception):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class ClassifierModelCorruptError(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger("paperless.classifier")
|
logger = logging.getLogger("paperless.classifier")
|
||||||
|
|
||||||
|
|
||||||
@ -34,9 +38,8 @@ def load_classifier():
|
|||||||
try:
|
try:
|
||||||
classifier.load()
|
classifier.load()
|
||||||
|
|
||||||
except (EOFError,
|
except (ClassifierModelCorruptError,
|
||||||
IncompatibleClassifierVersionError,
|
IncompatibleClassifierVersionError):
|
||||||
pickle.UnpicklingError):
|
|
||||||
# there's something wrong with the model file.
|
# there's something wrong with the model file.
|
||||||
logger.exception(
|
logger.exception(
|
||||||
f"Unrecoverable error while loading document "
|
f"Unrecoverable error while loading document "
|
||||||
@ -46,7 +49,12 @@ def load_classifier():
|
|||||||
classifier = None
|
classifier = None
|
||||||
except OSError:
|
except OSError:
|
||||||
logger.exception(
|
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
|
classifier = None
|
||||||
|
|
||||||
@ -76,13 +84,16 @@ class DocumentClassifier(object):
|
|||||||
raise IncompatibleClassifierVersionError(
|
raise IncompatibleClassifierVersionError(
|
||||||
"Cannor load classifier, incompatible versions.")
|
"Cannor load classifier, incompatible versions.")
|
||||||
else:
|
else:
|
||||||
self.data_hash = pickle.load(f)
|
try:
|
||||||
self.data_vectorizer = pickle.load(f)
|
self.data_hash = pickle.load(f)
|
||||||
self.tags_binarizer = pickle.load(f)
|
self.data_vectorizer = pickle.load(f)
|
||||||
|
self.tags_binarizer = pickle.load(f)
|
||||||
|
|
||||||
self.tags_classifier = pickle.load(f)
|
self.tags_classifier = pickle.load(f)
|
||||||
self.correspondent_classifier = pickle.load(f)
|
self.correspondent_classifier = pickle.load(f)
|
||||||
self.document_type_classifier = pickle.load(f)
|
self.document_type_classifier = pickle.load(f)
|
||||||
|
except Exception:
|
||||||
|
raise ClassifierModelCorruptError()
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
with open(settings.MODEL_FILE, "wb") as f:
|
with open(settings.MODEL_FILE, "wb") as f:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user