Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1daa817

Browse files
committed
fix: demote misleading LibreOffice 'not found' warning to debug (closes HKUDS#230)
On systems where only 'soffice' is on PATH (common on macOS), the existing fallback loop logged a WARNING for the 'libreoffice' candidate before successfully converting via 'soffice'. This caused users to see: WARNING: LibreOffice command 'libreoffice' not found INFO: Successfully converted file.pptx to PDF using soffice …and conclude that something was broken, even though the conversion succeeded. Fix: log FileNotFoundError at DEBUG level for any non-final candidate so that routine 'libreoffice' → 'soffice' fallback stays silent in normal logs. The WARNING is preserved only when the last candidate in the list is not found (meaning no usable LibreOffice binary exists at all and the conversion is about to fail).
1 parent 5fbff29 commit 1daa817

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

raganything/parser.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,9 @@ def convert_office_to_pdf(
146146
commands_to_try = ["libreoffice", "soffice"]
147147

148148
conversion_successful = False
149+
last_cmd = commands_to_try[-1]
149150
for cmd in commands_to_try:
151+
is_last = cmd == last_cmd
150152
try:
151153
convert_cmd = [
152154
cmd,
@@ -188,7 +190,17 @@ def convert_office_to_pdf(
188190
f"LibreOffice command '{cmd}' failed: {result.stderr}"
189191
)
190192
except FileNotFoundError:
191-
cls.logger.warning(f"LibreOffice command '{cmd}' not found")
193+
# Only warn when all candidates are exhausted; otherwise
194+
# log at debug level so that the normal fallback from
195+
# 'libreoffice' → 'soffice' does not surface a spurious
196+
# WARNING to users whose system only has 'soffice'.
197+
if is_last:
198+
cls.logger.warning(f"LibreOffice command '{cmd}' not found")
199+
else:
200+
cls.logger.debug(
201+
f"LibreOffice command '{cmd}' not found, "
202+
f"trying next candidate"
203+
)
192204
except subprocess.TimeoutExpired:
193205
cls.logger.warning(f"LibreOffice command '{cmd}' timed out")
194206
except Exception as e:

0 commit comments

Comments
 (0)