Skip to content

Commit 948f800

Browse files
authored
feat(core): improved exceptions for unwriteable internal storage (#1468)
1 parent c911989 commit 948f800

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Tempest\Core;
4+
5+
use Tempest\DateTime\Exception\RuntimeException;
6+
7+
final class CouldNotRegisterInternalStorage extends RuntimeException
8+
{
9+
public static function fileExists(string $path): self
10+
{
11+
return new self("Unable to create internal storage directory, as a file with the same name already exists at `{$path}`");
12+
}
13+
14+
public static function directoryNotWritable(string $path): self
15+
{
16+
return new self("Unable to create internal storage directory because of insufficient user permission on the root directory at `{$path}`");
17+
}
18+
19+
public static function noPermission(string $path): self
20+
{
21+
return new self("Insufficient user permission to write to internal storage directory as `{$path}`.");
22+
}
23+
}

packages/core/src/FrameworkKernel.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,14 @@ public function registerInternalStorage(): self
169169

170170
if (! is_dir($path)) {
171171
if (file_exists($path)) {
172-
throw new \RuntimeException('Unable to create internal storage directory, as a file with the same name (.tempest) already exists.');
172+
throw CouldNotRegisterInternalStorage::fileExists($path);
173173
}
174174

175175
if (! mkdir($path, recursive: true)) {
176-
throw new \RuntimeException('Unable to create internal storage directory because of insufficient user permission on the root directory.');
176+
throw CouldNotRegisterInternalStorage::directoryNotWritable($path);
177177
}
178178
} elseif (! is_writable($path)) {
179-
throw new \RuntimeException('Insufficient user permission to write to internal storage directory.');
179+
throw CouldNotRegisterInternalStorage::noPermission($path);
180180
}
181181

182182
$this->internalStorage = realpath($path);

0 commit comments

Comments
 (0)