Skip to content

Commit 7ba6b9f

Browse files
Merge pull request #136
Added `CloseFeedException`
2 parents e927597 + 5d6fad2 commit 7ba6b9f

File tree

3 files changed

+35
-12
lines changed

3 files changed

+35
-12
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace DragonCode\LaravelFeed\Exceptions;
6+
7+
use RuntimeException;
8+
use Throwable;
9+
10+
// @codeCoverageIgnoreStart
11+
class CloseFeedException extends RuntimeException
12+
{
13+
public function __construct(string $path, Throwable $e)
14+
{
15+
parent::__construct($e->getMessage() . ": [$path]", previous: $e);
16+
}
17+
}
18+
// @codeCoverageIgnoreEnd

src/Exceptions/OpenFeedException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class OpenFeedException extends RuntimeException
1212
{
1313
public function __construct(string $path, Throwable $e)
1414
{
15-
parent::__construct("Unable to open file for writing: [$path]", previous: $e);
15+
parent::__construct($e->getMessage() . ": [$path]", previous: $e);
1616
}
1717
}
1818
// @codeCoverageIgnoreEnd

src/Services/FilesystemService.php

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace DragonCode\LaravelFeed\Services;
66

7+
use DragonCode\LaravelFeed\Exceptions\CloseFeedException;
78
use DragonCode\LaravelFeed\Exceptions\OpenFeedException;
89
use DragonCode\LaravelFeed\Exceptions\ResourceMetaException;
910
use DragonCode\LaravelFeed\Exceptions\WriteFeedException;
@@ -73,22 +74,26 @@ public function append($resource, string $content, string $path): void // @pest-
7374
*/
7475
public function release($resource, string $path): void // @pest-ignore-type
7576
{
76-
$temp = $this->getMetaPath($resource);
77+
try {
78+
$temp = $this->getMetaPath($resource);
7779

78-
$this->unlock($resource);
79-
$this->close($resource);
80+
$this->unlock($resource);
81+
$this->close($resource);
8082

81-
if ($this->file->exists($path)) {
82-
$this->file->delete($path);
83-
}
83+
if ($this->file->exists($path)) {
84+
$this->file->delete($path);
85+
}
8486

85-
$this->file->ensureDirectoryExists(
86-
dirname($path)
87-
);
87+
$this->file->ensureDirectoryExists(
88+
dirname($path)
89+
);
8890

89-
$this->file->move($temp, $path);
91+
$this->file->move($temp, $path);
9092

91-
$this->cleanTemporaryDirectory($temp);
93+
$this->cleanTemporaryDirectory($temp);
94+
} catch (Throwable $e) {
95+
throw new CloseFeedException($path, $e);
96+
}
9297
}
9398

9499
/**

0 commit comments

Comments
 (0)