mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-11-03 03:16:10 -06:00 
			
		
		
		
	better exception logging
This commit is contained in:
		@@ -64,9 +64,9 @@ class Consumer(LoggingMixin):
 | 
			
		||||
                                                     {'type': 'status_update',
 | 
			
		||||
                                                      'data': payload})
 | 
			
		||||
 | 
			
		||||
    def _fail(self, message, log_message=None):
 | 
			
		||||
    def _fail(self, message, log_message=None, exc_info=None):
 | 
			
		||||
        self._send_progress(100, 100, 'FAILED', message)
 | 
			
		||||
        self.log("error", log_message or message)
 | 
			
		||||
        self.log("error", log_message or message, exc_info=exc_info)
 | 
			
		||||
        raise ConsumerError(f"{self.filename}: {log_message or message}")
 | 
			
		||||
 | 
			
		||||
    def __init__(self):
 | 
			
		||||
@@ -120,7 +120,8 @@ class Consumer(LoggingMixin):
 | 
			
		||||
        except Exception as e:
 | 
			
		||||
            self._fail(
 | 
			
		||||
                MESSAGE_PRE_CONSUME_SCRIPT_ERROR,
 | 
			
		||||
                f"Error while executing pre-consume script: {e}"
 | 
			
		||||
                f"Error while executing pre-consume script: {e}",
 | 
			
		||||
                exc_info=True
 | 
			
		||||
            )
 | 
			
		||||
 | 
			
		||||
    def run_post_consume_script(self, document):
 | 
			
		||||
@@ -150,7 +151,8 @@ class Consumer(LoggingMixin):
 | 
			
		||||
        except Exception as e:
 | 
			
		||||
            self._fail(
 | 
			
		||||
                MESSAGE_POST_CONSUME_SCRIPT_ERROR,
 | 
			
		||||
                f"Error while executing post-consume script: {e}"
 | 
			
		||||
                f"Error while executing post-consume script: {e}",
 | 
			
		||||
                exc_info=True
 | 
			
		||||
            )
 | 
			
		||||
 | 
			
		||||
    def try_consume_file(self,
 | 
			
		||||
@@ -255,7 +257,8 @@ class Consumer(LoggingMixin):
 | 
			
		||||
            document_parser.cleanup()
 | 
			
		||||
            self._fail(
 | 
			
		||||
                str(e),
 | 
			
		||||
                f"Error while consuming document {self.filename}: {e}"
 | 
			
		||||
                f"Error while consuming document {self.filename}: {e}",
 | 
			
		||||
                exc_info=True
 | 
			
		||||
            )
 | 
			
		||||
 | 
			
		||||
        # Prepare the document classifier.
 | 
			
		||||
@@ -326,7 +329,8 @@ class Consumer(LoggingMixin):
 | 
			
		||||
            self._fail(
 | 
			
		||||
                str(e),
 | 
			
		||||
                f"The following error occured while consuming "
 | 
			
		||||
                f"{self.filename}: {e}"
 | 
			
		||||
                f"{self.filename}: {e}",
 | 
			
		||||
                exc_info=True
 | 
			
		||||
            )
 | 
			
		||||
        finally:
 | 
			
		||||
            document_parser.cleanup()
 | 
			
		||||
 
 | 
			
		||||
@@ -246,9 +246,9 @@ class RasterisedDocumentParser(DocumentParser):
 | 
			
		||||
            if original_has_text:
 | 
			
		||||
                self.text = text_original
 | 
			
		||||
        except (NoTextFoundException, InputFileError) as e:
 | 
			
		||||
            self.log("exception",
 | 
			
		||||
                     f"Encountered the following error while running OCR, "
 | 
			
		||||
                     f"attempting force OCR to get the text.")
 | 
			
		||||
            self.log("warning",
 | 
			
		||||
                     f"Encountered an error while running OCR: {str(e)}. "
 | 
			
		||||
                     f"Attempting force OCR to get the text.")
 | 
			
		||||
 | 
			
		||||
            archive_path_fallback = os.path.join(
 | 
			
		||||
                self.tempdir, "archive-fallback.pdf")
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user