Raise exceptions instead of returning error strings in edit_pdf

This commit is contained in:
shamoon
2025-08-02 09:43:49 -04:00
parent 92b9c69806
commit 232f13f69b
3 changed files with 8 additions and 7 deletions

View File

@@ -532,7 +532,7 @@ def edit_pdf(
logger.error(
"Update requested but multiple output documents specified",
)
return "ERROR"
raise ValueError("Multiple output documents specified")
for op in operations:
dst = pdf_docs[op.get("doc", 0)]
@@ -583,7 +583,9 @@ def edit_pdf(
except Exception as e:
logger.exception(f"Error editing document {doc.id}: {e}")
return "ERROR"
raise ValueError(
f"An error occurred while editing the document: {e}",
) from e
return "OK"

View File

@@ -1032,8 +1032,8 @@ class TestPDFActions(DirectoriesMixin, TestCase):
{"page": 9999}, # invalid page, forces error during PDF load
]
with self.assertLogs("paperless.bulk_edit", level="ERROR"):
result = bulk_edit.edit_pdf(doc_ids, operations)
self.assertEqual(result, "ERROR")
with self.assertRaises(Exception):
bulk_edit.edit_pdf(doc_ids, operations)
mock_group.assert_not_called()
mock_consume_file.assert_not_called()
@@ -1058,7 +1058,7 @@ class TestPDFActions(DirectoriesMixin, TestCase):
{"page": 2, "doc": 1},
]
with self.assertLogs("paperless.bulk_edit", level="ERROR"):
result = bulk_edit.edit_pdf(doc_ids, operations, update_document=True)
self.assertEqual(result, "ERROR")
with self.assertRaises(ValueError):
bulk_edit.edit_pdf(doc_ids, operations, update_document=True)
mock_group.assert_not_called()
mock_consume_file.assert_not_called()

View File

@@ -1427,7 +1427,6 @@ class BulkEditView(PassUserMixin):
)
}
# TODO: parameter validation
result = method(documents, **parameters)
if settings.AUDIT_LOG_ENABLED and modified_field: