From 8e78c4154930738f1b7ca34cf230c27c4d25179e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 2 Sep 2025 21:53:40 +0200 Subject: [PATCH] Improve error handling when saving objects to local disk by using `dumpFile` with detailed exception logging. --- .changes/unreleased/DX-20250902-215127.yaml | 7 +++++++ .../Driver/LocalStorage/StoredObjectManager.php | 14 +++++--------- 2 files changed, 12 insertions(+), 9 deletions(-) create mode 100644 .changes/unreleased/DX-20250902-215127.yaml diff --git a/.changes/unreleased/DX-20250902-215127.yaml b/.changes/unreleased/DX-20250902-215127.yaml new file mode 100644 index 000000000..7d682d3ec --- /dev/null +++ b/.changes/unreleased/DX-20250902-215127.yaml @@ -0,0 +1,7 @@ +kind: DX +body: | + Improve error message when a stored object cannot be written on local disk +time: 2025-09-02T21:51:27.248966834+02:00 +custom: + Issue: "" + SchemaChange: No schema change diff --git a/src/Bundle/ChillDocStoreBundle/AsyncUpload/Driver/LocalStorage/StoredObjectManager.php b/src/Bundle/ChillDocStoreBundle/AsyncUpload/Driver/LocalStorage/StoredObjectManager.php index 09d277635..9174f42e6 100644 --- a/src/Bundle/ChillDocStoreBundle/AsyncUpload/Driver/LocalStorage/StoredObjectManager.php +++ b/src/Bundle/ChillDocStoreBundle/AsyncUpload/Driver/LocalStorage/StoredObjectManager.php @@ -18,6 +18,7 @@ use Chill\DocStoreBundle\Exception\StoredObjectManagerException; use Chill\DocStoreBundle\Service\Cryptography\KeyGenerator; use Chill\DocStoreBundle\Service\StoredObjectManagerInterface; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; +use Symfony\Component\Filesystem\Exception\IOExceptionInterface; use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Filesystem\Path; @@ -147,16 +148,11 @@ class StoredObjectManager implements StoredObjectManagerInterface public function writeContent(string $filename, string $encryptedContent): void { $fullPath = $this->buildPath($filename); - $dir = Path::getDirectory($fullPath); - if (!$this->filesystem->exists($dir)) { - $this->filesystem->mkdir($dir); - } - - $result = file_put_contents($fullPath, $encryptedContent); - - if (false === $result) { - throw StoredObjectManagerException::unableToStoreDocumentOnDisk(); + try { + $this->filesystem->dumpFile($fullPath, $encryptedContent); + } catch (IOExceptionInterface $exception) { + throw StoredObjectManagerException::unableToStoreDocumentOnDisk($exception); } }