mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-07-30 18:27:45 -05:00
When raising an exception during exception handling, chain them together for slightly cleaner logs
This commit is contained in:
@@ -101,8 +101,8 @@ class DocumentClassifier:
|
||||
self.correspondent_classifier = pickle.load(f)
|
||||
self.document_type_classifier = pickle.load(f)
|
||||
self.storage_path_classifier = pickle.load(f)
|
||||
except Exception:
|
||||
raise ClassifierModelCorruptError()
|
||||
except Exception as err:
|
||||
raise ClassifierModelCorruptError() from err
|
||||
|
||||
# Check for the warning about unpickling from differing versions
|
||||
# and consider it incompatible
|
||||
|
@@ -78,10 +78,16 @@ class Consumer(LoggingMixin):
|
||||
{"type": "status_update", "data": payload},
|
||||
)
|
||||
|
||||
def _fail(self, message, log_message=None, exc_info=None):
|
||||
def _fail(
|
||||
self,
|
||||
message,
|
||||
log_message=None,
|
||||
exc_info=None,
|
||||
exception: Optional[Exception] = None,
|
||||
):
|
||||
self._send_progress(100, 100, "FAILED", message)
|
||||
self.log("error", log_message or message, exc_info=exc_info)
|
||||
raise ConsumerError(f"{self.filename}: {log_message or message}")
|
||||
raise ConsumerError(f"{self.filename}: {log_message or message}") from exception
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
@@ -152,6 +158,7 @@ class Consumer(LoggingMixin):
|
||||
MESSAGE_PRE_CONSUME_SCRIPT_ERROR,
|
||||
f"Error while executing pre-consume script: {e}",
|
||||
exc_info=True,
|
||||
exception=e,
|
||||
)
|
||||
|
||||
def run_post_consume_script(self, document):
|
||||
@@ -217,6 +224,7 @@ class Consumer(LoggingMixin):
|
||||
MESSAGE_POST_CONSUME_SCRIPT_ERROR,
|
||||
f"Error while executing post-consume script: {e}",
|
||||
exc_info=True,
|
||||
exception=e,
|
||||
)
|
||||
|
||||
def try_consume_file(
|
||||
@@ -331,6 +339,7 @@ class Consumer(LoggingMixin):
|
||||
str(e),
|
||||
f"Error while consuming document {self.filename}: {e}",
|
||||
exc_info=True,
|
||||
exception=e,
|
||||
)
|
||||
|
||||
# Prepare the document classifier.
|
||||
@@ -415,6 +424,7 @@ class Consumer(LoggingMixin):
|
||||
f"The following error occurred while consuming "
|
||||
f"{self.filename}: {e}",
|
||||
exc_info=True,
|
||||
exception=e,
|
||||
)
|
||||
finally:
|
||||
document_parser.cleanup()
|
||||
|
Reference in New Issue
Block a user