mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-07 08:45:40 +08:00
Refactor all (except command) modules using new exceptions
This commit is contained in:
@@ -5,7 +5,7 @@ declare(strict_types=1);
|
||||
namespace SPC\util;
|
||||
|
||||
use SPC\builder\macos\SystemUtil;
|
||||
use SPC\exception\RuntimeException;
|
||||
use SPC\exception\SPCInternalException;
|
||||
use SPC\exception\WrongUsageException;
|
||||
use SPC\toolchain\ToolchainManager;
|
||||
|
||||
@@ -33,7 +33,7 @@ class GlobalEnvManager
|
||||
}
|
||||
// Check pre-defined env vars exists
|
||||
if (getenv('BUILD_ROOT_PATH') === false) {
|
||||
throw new RuntimeException('You must include src/globals/internal-env.php before using GlobalEnvManager');
|
||||
throw new SPCInternalException('You must include src/globals/internal-env.php before using GlobalEnvManager');
|
||||
}
|
||||
|
||||
// Define env vars for unix
|
||||
|
||||
@@ -4,9 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace SPC\util;
|
||||
|
||||
use SPC\exception\FileSystemException;
|
||||
use SPC\exception\RuntimeException;
|
||||
use SPC\exception\WrongUsageException;
|
||||
use SPC\exception\SPCInternalException;
|
||||
use SPC\store\Config;
|
||||
use SPC\store\FileSystem;
|
||||
|
||||
@@ -100,7 +98,7 @@ class LicenseDumper
|
||||
{
|
||||
$licenses = Config::getSource($source_name)['license'] ?? [];
|
||||
if ($licenses === []) {
|
||||
throw new RuntimeException('source [' . $source_name . '] license meta not exist');
|
||||
throw new SPCInternalException("source [{$source_name}] license meta not exist");
|
||||
}
|
||||
|
||||
if (!array_is_list($licenses)) {
|
||||
@@ -111,7 +109,7 @@ class LicenseDumper
|
||||
yield $index => match ($license['type']) {
|
||||
'text' => $license['text'],
|
||||
'file' => $this->loadSourceFile($source_name, $index, $license['path'], Config::getSource($source_name)['path'] ?? null),
|
||||
default => throw new RuntimeException('source [' . $source_name . '] license type is not allowed'),
|
||||
default => throw new SPCInternalException("source [{$source_name}] license type is not allowed"),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -122,7 +120,7 @@ class LicenseDumper
|
||||
private function loadSourceFile(string $source_name, int $index, null|array|string $in_path, ?string $custom_base_path = null): string
|
||||
{
|
||||
if (is_null($in_path)) {
|
||||
throw new RuntimeException('source [' . $source_name . '] license file is not set, please check config/source.json');
|
||||
throw new SPCInternalException("source [{$source_name}] license file is not set, please check config/source.json");
|
||||
}
|
||||
|
||||
if (!is_array($in_path)) {
|
||||
@@ -139,6 +137,6 @@ class LicenseDumper
|
||||
return file_get_contents(BUILD_ROOT_PATH . '/source-licenses/' . $source_name . '/' . $index . '.txt');
|
||||
}
|
||||
|
||||
throw new RuntimeException('Cannot find any license file in source [' . $source_name . '] directory!');
|
||||
throw new SPCInternalException("Cannot find any license file in source [{$source_name}] directory!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace SPC\util;
|
||||
|
||||
use SPC\exception\RuntimeException;
|
||||
use SPC\exception\ExecutionException;
|
||||
|
||||
/**
|
||||
* Utility class for pkg-config operations
|
||||
@@ -95,7 +95,7 @@ class PkgConfigUtil
|
||||
{
|
||||
f_exec($cmd, $output, $result_code);
|
||||
if ($result_code !== 0) {
|
||||
throw new RuntimeException("pkg-config command failed with code {$result_code}: {$cmd}");
|
||||
throw new ExecutionException($cmd, "pkg-config command failed with code: {$result_code}");
|
||||
}
|
||||
return implode("\n", $output);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user