Repository: paperless-ngx/paperless-ngx

Issue:
[BUG] OS reports file as busy – wrong error message?!
### Description

Hello everyone,

I have setup paperless-ngx in Docker in my Synology NAS. I have created a bind mount for the `data/consume` folder and threw in some pdf files. However I always got an error `OS reports file as busy still`. Now, I've made sure that no other client is accessing the file. And the file can be opened from any other network device and the NAS web interface. Turns out, this was actually a permissions issue with wrong User IDs. So, the error message is factually not correct.

So I am under the impression that the error message is not very precise. From my little Python knowledge, I've looked[ at the code](https://github.com/paperless-ngx/paperless-ngx/blob/4df065d8d524870ec18e8fbf2fc488449939a044/src/documents/management/commands/document_consumer.py#L74) and it seems to be a very [generic Exception](https://docs.python.org/3/library/exceptions.html#OSError). It could also be thrown, when the disk is full, etc. There is a specific error number in the Exception. Would it make sense, to add that to the error output in the log and/or to change the message?

### Steps to reproduce

There's already a test for it, if you want to trigger the error message on purpose.

### Webserver logs

```bash
[2022-06-20 10:22:37,016] [WARNING] [paperless.management.consumer] Not consuming file /data/consume/E79221B2X115146_06202022_122344_000002.pdf: OS reports file as busy still

[2022-06-20 10:26:20,714] [WARNING] [paperless.management.consumer] Not consuming file /data/consume/E79221B2X115146_06202022_122344_000003.pdf: OS reports file as busy still

[2022-06-20 10:26:47,094] [WARNING] [paperless.management.consumer] Not consuming file /data/consume/.DS_Store: Unknown file extension.

[2022-06-20 10:26:48,738] [WARNING] [paperless.management.consumer] Not consuming file /data/consume/Fragebogen-Mehrfachbeschäftigung-Minijob.pdf: OS reports file as busy still

[2022-06-20 10:26:53,120] [WARNING] [paperless.management.consumer] Not consuming file /data/consume/.DS_Store: Unknown file extension.
```


### Paperless-ngx version

1.7.1

### Host OS

Synology DSM 7

### Installation method

Docker

### Browser

_No response_

### Configuration changes

_No response_

### Other

_No response_


Discussion:
It would. Or optionally check the errno of the OSError we're catching here. But a more generic message with the actual exception message makes sense

Resolving patch:
diff --git a/src/documents/management/commands/document_consumer.py b/src/documents/management/commands/document_consumer.py
--- a/src/documents/management/commands/document_consumer.py
+++ b/src/documents/management/commands/document_consumer.py
@@ -67,17 +67,19 @@ def _consume(filepath):
 
     read_try_count = 0
     file_open_ok = False
+    os_error_str = None
 
     while (read_try_count < os_error_retry_count) and not file_open_ok:
         try:
             with open(filepath, "rb"):
                 file_open_ok = True
-        except OSError:
+        except OSError as e:
             read_try_count += 1
+            os_error_str = str(e)
             sleep(os_error_retry_wait)
 
     if read_try_count >= os_error_retry_count:
-        logger.warning(f"Not consuming file {filepath}: OS reports file as busy still")
+        logger.warning(f"Not consuming file {filepath}: OS reports {os_error_str}")
         return
 
     tag_ids = None


Test patch: