mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-07 08:45:40 +08:00
Enhance error handling in artifact downloading process
This commit is contained in:
@@ -10,4 +10,15 @@ namespace StaticPHP\Exception;
|
||||
* This exception is used to indicate that a download operation has failed,
|
||||
* typically due to network issues, invalid URLs, or other related problems.
|
||||
*/
|
||||
class DownloaderException extends SPCException {}
|
||||
class DownloaderException extends SPCException
|
||||
{
|
||||
public function __construct(string $message = '', int $code = 0, ?\Throwable $previous = null, private readonly ?string $artifact_name = null)
|
||||
{
|
||||
parent::__construct($message, $code, $previous);
|
||||
}
|
||||
|
||||
public function getArtifactName(): ?string
|
||||
{
|
||||
return $this->artifact_name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ class ExceptionHandler
|
||||
}
|
||||
}
|
||||
if (!ApplicationContext::isDebug()) {
|
||||
self::logError('⚠ If you want to see more details in console, use `-vvv` option.');
|
||||
self::logError('⚠ If you want to see more details in console, use `-v`, `-vv` or `-vvv` option.');
|
||||
}
|
||||
return self::getReturnCode($e);
|
||||
}
|
||||
@@ -232,6 +232,9 @@ class ExceptionHandler
|
||||
if ($e instanceof ExecutionException) {
|
||||
self::logError('');
|
||||
self::logError('Failed command: ' . ConsoleColor::gray($e->getExecutionCommand()));
|
||||
if ($e->getCode() !== 0) {
|
||||
self::logError(' - Exit code: ' . ConsoleColor::gray((string) $e->getCode()));
|
||||
}
|
||||
if ($cd = $e->getCd()) {
|
||||
self::logError(' - Command executed in: ' . ConsoleColor::gray($cd));
|
||||
}
|
||||
@@ -243,6 +246,26 @@ class ExceptionHandler
|
||||
}
|
||||
}
|
||||
|
||||
// get downloader info
|
||||
if ($e instanceof DownloaderException) {
|
||||
if ($artifact_name = $e->getArtifactName()) {
|
||||
self::logError('Failed artifact: ' . ConsoleColor::gray($artifact_name));
|
||||
}
|
||||
$cause = $e->getPrevious();
|
||||
if ($cause instanceof ExecutionException) {
|
||||
self::logError('');
|
||||
self::logError('Last failed command: ' . ConsoleColor::gray($cause->getExecutionCommand()));
|
||||
if ($cause->getCode() !== 0) {
|
||||
self::logError(' - Exit code: ' . ConsoleColor::gray((string) $cause->getCode()));
|
||||
}
|
||||
if ($cd = $cause->getCd()) {
|
||||
self::logError(' - Command executed in: ' . ConsoleColor::gray($cd));
|
||||
}
|
||||
} elseif ($cause instanceof DownloaderException || $cause instanceof ValidationException) {
|
||||
self::logError('Cause: ' . ConsoleColor::gray($cause->getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
// validation error
|
||||
if ($e instanceof ValidationException) {
|
||||
self::logError('Failed validation module: ' . ConsoleColor::gray($e->getValidationModuleString()));
|
||||
|
||||
Reference in New Issue
Block a user