diff --git a/src/Exceptions/CloseFeedException.php b/src/Exceptions/CloseFeedException.php new file mode 100644 index 0000000..6235161 --- /dev/null +++ b/src/Exceptions/CloseFeedException.php @@ -0,0 +1,18 @@ +getMessage() . ": [$path]", previous: $e); + } +} +// @codeCoverageIgnoreEnd diff --git a/src/Exceptions/OpenFeedException.php b/src/Exceptions/OpenFeedException.php index 3829500..ed25917 100644 --- a/src/Exceptions/OpenFeedException.php +++ b/src/Exceptions/OpenFeedException.php @@ -12,7 +12,7 @@ class OpenFeedException extends RuntimeException { public function __construct(string $path, Throwable $e) { - parent::__construct("Unable to open file for writing: [$path]", previous: $e); + parent::__construct($e->getMessage() . ": [$path]", previous: $e); } } // @codeCoverageIgnoreEnd diff --git a/src/Services/FilesystemService.php b/src/Services/FilesystemService.php index 03ef4da..83161c3 100644 --- a/src/Services/FilesystemService.php +++ b/src/Services/FilesystemService.php @@ -4,6 +4,7 @@ namespace DragonCode\LaravelFeed\Services; +use DragonCode\LaravelFeed\Exceptions\CloseFeedException; use DragonCode\LaravelFeed\Exceptions\OpenFeedException; use DragonCode\LaravelFeed\Exceptions\ResourceMetaException; use DragonCode\LaravelFeed\Exceptions\WriteFeedException; @@ -73,22 +74,26 @@ public function append($resource, string $content, string $path): void // @pest- */ public function release($resource, string $path): void // @pest-ignore-type { - $temp = $this->getMetaPath($resource); + try { + $temp = $this->getMetaPath($resource); - $this->unlock($resource); - $this->close($resource); + $this->unlock($resource); + $this->close($resource); - if ($this->file->exists($path)) { - $this->file->delete($path); - } + if ($this->file->exists($path)) { + $this->file->delete($path); + } - $this->file->ensureDirectoryExists( - dirname($path) - ); + $this->file->ensureDirectoryExists( + dirname($path) + ); - $this->file->move($temp, $path); + $this->file->move($temp, $path); - $this->cleanTemporaryDirectory($temp); + $this->cleanTemporaryDirectory($temp); + } catch (Throwable $e) { + throw new CloseFeedException($path, $e); + } } /**