Shorter short error messages.
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user