From 7ac373179b438247b551a7f24cc98be2994a64e4 Mon Sep 17 00:00:00 2001 From: Leo Vasanko Date: Thu, 13 Aug 2026 05:19:50 +0000 Subject: [PATCH] Shorter short error messages. --- mediapreview/exceptions.py | 10 +++++++++- tests/test_office.py | 9 +++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/mediapreview/exceptions.py b/mediapreview/exceptions.py index 6fa5821..e5cf2b3 100644 --- a/mediapreview/exceptions.py +++ b/mediapreview/exceptions.py @@ -154,7 +154,15 @@ def onlyoffice_no_fileurl_error(snippet: str | None = None) -> OnlyOfficeError: def backend_error(backend: str, message: str) -> PreviewBackendError: - short = message.splitlines()[0][:60] + short = message.splitlines()[0] + # Many backend messages look like "source: summary: detail ...". + # Drop the source prefix and any trailing detail so the short label + # is usable in UIs with limited space. + if ": " in short: + short = short.split(": ", 1)[1] + if ": " in short: + short = short.split(": ", 1)[0] + short = short[:60] return PreviewBackendError( f"[{backend}] preview failed: {message}", short, diff --git a/tests/test_office.py b/tests/test_office.py index de0bee0..99e055f 100644 --- a/tests/test_office.py +++ b/tests/test_office.py @@ -72,6 +72,15 @@ def test_backend_error_pipeline_backend(): assert isinstance(err, PreviewBackendError) +def test_backend_error_short_message_strips_source_and_detail(): + """Backend messages like "source: summary: detail" become just the summary.""" + err = backend_error( + "vips", + "pyvips: cannot decode image: unable to load from file b'/mnt/c/Users...", + ) + assert err.short == "cannot decode image" + + def test_error_pickle_round_trip(): """Exceptions survive pickling (the worker pool wire) intact.""" err = onlyoffice_error_from_code("-8")