diff --git a/lib/AbstractException.php b/lib/AbstractException.php index d2cb0d5..47caf39 100644 --- a/lib/AbstractException.php +++ b/lib/AbstractException.php @@ -102,6 +102,10 @@ abstract class AbstractException extends \Exception { "ImportExport/Exception.invalidFolderCopy" => 10614, "ImportExport/Exception.invalidTagName" => 10615, "Rule/Exception.invalidPattern" => 10701, + "CLI/Exception.pidNotFile" => 10801, + "CLI/Exception.pidDirNotFound" => 10802, + "CLI/Exception.pidUnwritable" => 10803, + "CLI/Exception.pidUncreatable" => 10804, ]; protected $symbol; diff --git a/lib/CLI.php b/lib/CLI.php index c52c508..433502e 100644 --- a/lib/CLI.php +++ b/lib/CLI.php @@ -331,24 +331,24 @@ USAGE_TEXT; } /** Resolves the PID file path and ensures the file or parent directory is writable */ - protected function resolvePID(string $pidfile): string { + public function resolvePID(string $pidfile): string { $dir = dirname($pidfile); $file = basename($pidfile); if (!strlen($file)) { - throw new \Exception("Specified PID file location must be a regular file"); + throw new CLI\Exception("pidNotFile", ['pidfile' => $dir]); } elseif ($base = @realpath($dir)) { $out = "$base/$file"; if (file_exists($out)) { if (!is_writable($out)) { throw new \Exception("PID file is not writable"); } elseif (!is_file($out)) { - throw new \Exception("Specified PID file location must be a regular file"); + throw new CLI\Exception("pidNotFile", ['pidfile' => $out]); } } elseif (!is_writable($base)) { throw new \Exception("Cannot create PID file"); } } else { - throw new \Exception("Parent directory of PID file does not exist"); + throw new \Exception("pidDirNotFound", ['piddir' => $dir]); } return $out; } diff --git a/lib/CLI/Exception.php b/lib/CLI/Exception.php new file mode 100644 index 0000000..7fe7c79 --- /dev/null +++ b/lib/CLI/Exception.php @@ -0,0 +1,10 @@ + 'Input data contains an invalid folder name', 'Exception.JKingWeb/Arsse/ImportExport/Exception.invalidFolderCopy' => 'Input data contains multiple folders of the same name under the same parent', 'Exception.JKingWeb/Arsse/ImportExport/Exception.invalidTagName' => 'Input data contains an invalid tag name', - 'Exception.JKingWeb/Arsse/Rule/Exception.invalidPattern' => 'Specified rule pattern is invalid' + 'Exception.JKingWeb/Arsse/Rule/Exception.invalidPattern' => 'Specified rule pattern is invalid', + 'Exception.JKingWeb/Arsse/CLI/Exception.pidNotFile' => 'Specified PID file location "{pidfile}" must be a regular file', + 'Exception.JKingWeb/Arsse/CLI/Exception.pidDirNotFound' => 'Parent directory "{piddir}" of PID file does not exist', + 'Exception.JKingWeb/Arsse/CLI/Exception.pidUnwritable' => 'Insufficient permissions to open PID file "{pidfile}" for writing', + 'Exception.JKingWeb/Arsse/CLI/Exception.pidNotFile' => 'Specified PID file location "{pidfile}" must be a regular file', ];