From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Sat, 2 Aug 2025 13:43:49 +0000 (-0400) Subject: Raise exceptions instead of returning error strings in edit_pdf X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a5ab90de345cc5f1ce35e74655d7d590483b36d1;p=thirdparty%2Fpaperless-ngx.git Raise exceptions instead of returning error strings in edit_pdf --- diff --git a/src/documents/bulk_edit.py b/src/documents/bulk_edit.py index af6be45b6..8ef807da8 100644 --- a/src/documents/bulk_edit.py +++ b/src/documents/bulk_edit.py @@ -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" diff --git a/src/documents/tests/test_bulk_edit.py b/src/documents/tests/test_bulk_edit.py index 8af641ed4..4e6200719 100644 --- a/src/documents/tests/test_bulk_edit.py +++ b/src/documents/tests/test_bulk_edit.py @@ -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() diff --git a/src/documents/views.py b/src/documents/views.py index 6c9ce38dd..c98df6da4 100644 --- a/src/documents/views.py +++ b/src/documents/views.py @@ -1427,7 +1427,6 @@ class BulkEditView(PassUserMixin): ) } - # TODO: parameter validation result = method(documents, **parameters) if settings.AUDIT_LOG_ENABLED and modified_field: