Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add path not exists exception which specifies the path #41

Open
wants to merge 5 commits into
base: 2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/ParallelDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,12 @@ public function size(string $path): Promise
return call(function () use ($path) {
$stat = yield $this->stat($path);
if (empty($stat)) {
throw new FilesystemException("Specified path does not exist");
throw new PathDoesNotExistException($path);
}
if ($stat["mode"] & 0100000) {
return $stat["size"];
}
throw new FilesystemException("Specified path is not a regular file");
throw new FilesystemException(sprintf('Specified path "%s" is not a regular file', $path));
});
}

Expand All @@ -228,7 +228,7 @@ public function mtime(string $path): Promise
return call(function () use ($path) {
$stat = yield $this->stat($path);
if (empty($stat)) {
throw new FilesystemException("Specified path does not exist");
throw new PathDoesNotExistException($path);
}
return $stat["mtime"];
});
Expand All @@ -242,7 +242,7 @@ public function atime(string $path): Promise
return call(function () use ($path) {
$stat = yield $this->stat($path);
if (empty($stat)) {
throw new FilesystemException("Specified path does not exist");
throw new PathDoesNotExistException($path);
}
return $stat["atime"];
});
Expand All @@ -256,7 +256,7 @@ public function ctime(string $path): Promise
return call(function () use ($path) {
$stat = yield $this->stat($path);
if (empty($stat)) {
throw new FilesystemException("Specified path does not exist");
throw new PathDoesNotExistException($path);
}
return $stat["ctime"];
});
Expand Down
13 changes: 13 additions & 0 deletions src/PathDoesNotExistException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Amp\File;

use Exception;

class PathDoesNotExistException extends FileSystemException
{
public function __construct(string $path)
{
parent::__construct(sprintf('Specified path "%s" does not exist', $path));
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend also adding a getter for the path. It might help custom exception handling.