Skip to content

A community-supported supercharged document management system: scan, index and archive all your documents

Chore: fix sonarcube logger warnings

shamoon15682231b26f
diff --git a/src/documents/plugins/date_parsing/__init__.py b/src/documents/plugins/date_parsing/__init__.py
index 2eec1e242..a96f440a4 100644
--- a/src/documents/plugins/date_parsing/__init__.py
+++ b/src/documents/plugins/date_parsing/__init__.py
@@ -44,7 +44,7 @@ def _discover_parser_class() -> type[DateParserPluginBase]:
else:
logger.warning(f"Plugin {ep.name} does not subclass DateParser.")
except Exception as e:
- logger.error(f"Unable to load date parser plugin {ep.name}: {e}")
+ logger.exception(f"Unable to load date parser plugin {ep.name}: {e}")
if not valid_plugins:
return RegexDateParserPlugin
diff --git a/src/documents/plugins/date_parsing/base.py b/src/documents/plugins/date_parsing/base.py
index 9605fe808..fd45ceec8 100644
--- a/src/documents/plugins/date_parsing/base.py
+++ b/src/documents/plugins/date_parsing/base.py
@@ -92,7 +92,7 @@ class DateParserPluginBase(ABC):
locales=self.config.languages,
)
except Exception as e:
- logger.error(f"Error while parsing date string '{date_string}': {e}")
+ logger.exception(f"Error while parsing date string '{date_string}': {e}")
return None
def _filter_date(
diff --git a/src/documents/regex.py b/src/documents/regex.py
index 849d417d8..0c5f4aac6 100644
--- a/src/documents/regex.py
+++ b/src/documents/regex.py
@@ -60,7 +60,7 @@ def safe_regex_match(pattern: str, text: str, *, flags: int = 0):
validate_regex_pattern(pattern)
compiled = regex.compile(pattern, flags=flags)
except (regex.error, ValueError) as exc:
- logger.error(
+ logger.exception(
"Error while processing regular expression %s: %s",
textwrap.shorten(pattern, width=80, placeholder="…"),
exc,
@@ -87,7 +87,7 @@ def safe_regex_sub(pattern: str, repl: str, text: str, *, flags: int = 0) -> str
validate_regex_pattern(pattern)
compiled = regex.compile(pattern, flags=flags)
except (regex.error, ValueError) as exc:
- logger.error(
+ logger.exception(
"Error while processing regular expression %s: %s",
textwrap.shorten(pattern, width=80, placeholder="…"),
exc,
diff --git a/src/paperless/parsers/remote.py b/src/paperless/parsers/remote.py
index c851469aa..41989d834 100644
--- a/src/paperless/parsers/remote.py
+++ b/src/paperless/parsers/remote.py
@@ -425,7 +425,7 @@ class RemoteDocumentParser:
return result.content
except Exception as e:
- logger.error("Azure AI Vision parsing failed: %s", e)
+ logger.exception("Azure AI Vision parsing failed: %s", e)
finally:
client.close()
diff --git a/src/paperless/tests/parsers/test_remote_parser.py b/src/paperless/tests/parsers/test_remote_parser.py
index b9e038e60..99d3342be 100644
--- a/src/paperless/tests/parsers/test_remote_parser.py
+++ b/src/paperless/tests/parsers/test_remote_parser.py
@@ -373,8 +373,8 @@ class TestRemoteParserParseError:
remote_parser.parse(simple_digital_pdf_file, "application/pdf")
- mock_log.error.assert_called_once()
- assert "Azure AI Vision parsing failed" in mock_log.error.call_args[0][0]
+ mock_log.exception.assert_called_once()
+ assert "Azure AI Vision parsing failed" in mock_log.exception.call_args[0][0]
# ---------------------------------------------------------------------------