diff --git a/CHANGELOG.md b/CHANGELOG.md index f042b5f..1ce43dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [1.0.4] - Unreleased This update introduces major changes in the codebase, including the removal of Win32 support, and the addition of new -features. +features and reduced the number of exceptions down to 15 exceptions. + ### Added - `LICENSE.md` & `license.md` are now detected as license files in `\ncc\Classes\ComposerExtension > ComposerSourceBuiltin > convertProject()` @@ -17,6 +18,7 @@ features. - Added a new interface class `BytecodeObjectInterface` which will be used to implement object types for compiled assets - Added new exception `GitException` in `\ncc\Exceptions` to replace all git related exceptions - Added new exception `PackageException` in `\ncc\Exceptions` to replace all package related exceptions + - Added new exception `OperationException` in `\ncc\Exceptions` to replace all generic related exceptions ### Fixed - Fixed MITM attack vector in `\ncc\Classes > HttpClient > prepareCurl()` @@ -167,6 +169,10 @@ features. - Removed unused exception `AutoloadGeneratorException` in `\ncc\Exceptions` in favor for `IOException` - Removed unused exception `SymlinkException` in `\ncc\Exceptions` in favor for `IOException` - Removed unused exception `PackageLockException` in `\ncc\Exceptions` in favor for `IOException` + - Removed unused exception `UnitsNotFoundException` in `\ncc\Exceptions` (not used) + - Removed unused exception `NoAvailableUnitsException` in `\ncc\Exceptions` in favor for `OperationException` + - Removed unused exception `InstallationException` in `\ncc\Exceptions` in favor for `OperationException` + - Removed all unused exceptions from the project, reduced the number of exceptions in total. diff --git a/scratch/exceptions_plan.txt b/scratch/exceptions_plan.txt index 8c255c5..c369e79 100644 --- a/scratch/exceptions_plan.txt +++ b/scratch/exceptions_plan.txt @@ -22,8 +22,8 @@ AuthenticationException * AUTHENTICATION_EXCEPTION ResourceNotFoundException - PROJECT_ALREADY_EXISTS - NO_UNITS_FOUND + - PROJECT_ALREADY_EXISTS + - NO_UNITS_FOUND VERSION_NOT_FOUND NO_AVAILABLE_UNITS @@ -71,7 +71,8 @@ NotSupportedException * UNSUPPORTED_REMOTE_SOURCE_TYPE * UNSUPPORTED_PACKAGE -RuntimeException +OperationException + RUNTIME_EXCEPTION RUNTIME BUILD_EXCEPTION RUNNER_EXECUTION_EXCEPTION diff --git a/src/ncc/CLI/Management/ProjectMenu.php b/src/ncc/CLI/Management/ProjectMenu.php index d08961b..26b948b 100644 --- a/src/ncc/CLI/Management/ProjectMenu.php +++ b/src/ncc/CLI/Management/ProjectMenu.php @@ -28,7 +28,6 @@ use ncc\Enums\CompilerExtensionSupportedVersions; use ncc\Exceptions\ConfigurationException; use ncc\Exceptions\IOException; - use ncc\Exceptions\MalformedJsonException; use ncc\Exceptions\PathNotFoundException; use ncc\Managers\ProjectManager; use ncc\Objects\CliHelpSection; @@ -45,7 +44,6 @@ * @return void * @throws ConfigurationException * @throws IOException - * @throws MalformedJsonException * @throws PathNotFoundException */ public static function start($args): void @@ -65,7 +63,6 @@ * @return void * @throws ConfigurationException * @throws IOException - * @throws MalformedJsonException * @throws PathNotFoundException */ public static function createProject($args): void diff --git a/src/ncc/Classes/ComposerExtension/ComposerSourceBuiltin.php b/src/ncc/Classes/ComposerExtension/ComposerSourceBuiltin.php index 18e9292..b88deba 100644 --- a/src/ncc/Classes/ComposerExtension/ComposerSourceBuiltin.php +++ b/src/ncc/Classes/ComposerExtension/ComposerSourceBuiltin.php @@ -36,12 +36,11 @@ use ncc\Exceptions\ComposerException; use ncc\Exceptions\ConfigurationException; use ncc\Exceptions\NotSupportedException; + use ncc\Exceptions\OperationException; use ncc\Exceptions\PackageException; use ncc\Exceptions\PathNotFoundException; use ncc\Exceptions\IOException; - use ncc\Exceptions\MalformedJsonException; use ncc\Exceptions\RuntimeException; - use ncc\Exceptions\UserAbortedOperationException; use ncc\Interfaces\ServiceSourceInterface; use ncc\Managers\ProjectManager; use ncc\ncc; @@ -78,12 +77,11 @@ * @throws ComposerException * @throws ConfigurationException * @throws IOException - * @throws MalformedJsonException * @throws NotSupportedException + * @throws OperationException * @throws PackageException * @throws PathNotFoundException * @throws RuntimeException - * @throws UserAbortedOperationException */ public static function fetch(RemotePackageInput $packageInput): string { @@ -113,11 +111,10 @@ * @throws ComposerException * @throws ConfigurationException * @throws IOException - * @throws MalformedJsonException * @throws NotSupportedException + * @throws OperationException * @throws PackageException * @throws PathNotFoundException - * @throws UserAbortedOperationException */ public static function fromLocal(string $path): string { @@ -182,7 +179,6 @@ * @throws BuildException * @throws ConfigurationException * @throws IOException - * @throws MalformedJsonException * @throws NotSupportedException * @throws PackageException * @throws PathNotFoundException @@ -202,7 +198,7 @@ } catch(JsonException $e) { - throw new MalformedJsonException($composer_lock_path, $e); + throw new IOException($composer_lock_path, $e); } $filesystem = new Filesystem(); @@ -508,8 +504,8 @@ * @return string * @throws ComposerException * @throws IOException + * @throws OperationException * @throws PathNotFoundException - * @throws UserAbortedOperationException */ private static function require(string $vendor, string $package, ?string $version = null): string { @@ -627,7 +623,7 @@ * @param string $path * @param array $options * @return void - * @throws UserAbortedOperationException + * @throws OperationException */ private static function prepareProcess(Process $process, string $path, array $options): void { @@ -642,7 +638,7 @@ { if(!Console::getBooleanInput('Do you want to continue?')) { - throw new UserAbortedOperationException('The operation was aborted by the user'); + throw new OperationException('The operation was aborted by the user'); } // The user understands the risks and wants to continue @@ -664,7 +660,6 @@ * @param mixed $composer_package * @return ProjectConfiguration * @throws IOException - * @throws MalformedJsonException * @throws PackageException * @throws PathNotFoundException */ diff --git a/src/ncc/Classes/GithubExtension/GithubService.php b/src/ncc/Classes/GithubExtension/GithubService.php index 972e0ba..06b87ec 100644 --- a/src/ncc/Classes/GithubExtension/GithubService.php +++ b/src/ncc/Classes/GithubExtension/GithubService.php @@ -27,9 +27,7 @@ use ncc\Classes\HttpClient; use ncc\Exceptions\AuthenticationException; use ncc\Exceptions\GitException; - use ncc\Exceptions\MalformedJsonException; use ncc\Exceptions\NetworkException; - use ncc\Exceptions\VersionNotFoundException; use ncc\Interfaces\RepositorySourceInterface; use ncc\Objects\DefinedRemoteSource; use ncc\Objects\HttpRequest; @@ -50,7 +48,6 @@ * @return RepositoryQueryResults * @throws AuthenticationException * @throws GitException - * @throws MalformedJsonException * @throws NetworkException */ public static function getGitRepository(RemotePackageInput $packageInput, DefinedRemoteSource $definedRemoteSource, ?Entry $entry = null): RepositoryQueryResults @@ -82,9 +79,7 @@ * @return RepositoryQueryResults * @throws AuthenticationException * @throws GitException - * @throws MalformedJsonException * @throws NetworkException - * @throws VersionNotFoundException */ public static function getRelease(RemotePackageInput $package_input, DefinedRemoteSource $defined_remote_source, ?Entry $entry = null): RepositoryQueryResults { @@ -98,9 +93,7 @@ * @return RepositoryQueryResults * @throws AuthenticationException * @throws GitException - * @throws MalformedJsonException * @throws NetworkException - * @throws VersionNotFoundException */ public static function getNccPackage(RemotePackageInput $packageInput, DefinedRemoteSource $definedRemoteSource, ?Entry $entry = null): RepositoryQueryResults { @@ -116,7 +109,6 @@ * @return array * @throws AuthenticationException * @throws GitException - * @throws MalformedJsonException * @throws NetworkException */ private static function getReleases(RemotePackageInput $packageInput, DefinedRemoteSource $definedRemoteSource, ?Entry $entry = null): array @@ -188,7 +180,6 @@ * @return array * @throws AuthenticationException * @throws GitException - * @throws MalformedJsonException * @throws NetworkException */ private static function getJsonResponse(HttpRequest $httpRequest, ?Entry $entry): array @@ -215,9 +206,7 @@ * @return mixed * @throws AuthenticationException * @throws GitException - * @throws MalformedJsonException * @throws NetworkException - * @throws VersionNotFoundException */ private static function processReleases(RemotePackageInput $packageInput, DefinedRemoteSource $definedRemoteSource, ?Entry $entry): mixed { @@ -225,7 +214,7 @@ if (count($releases) === 0) { - throw new VersionNotFoundException('No releases found for the given repository.'); + throw new GitException(sprintf('No releases found for %s/%s on %s.', $packageInput->vendor, $packageInput->package, $definedRemoteSource->host)); } if ($packageInput->version === Versions::LATEST) @@ -269,7 +258,7 @@ if ($selected_version === null) { - throw new VersionNotFoundException('No releases found for the given repository.'); + throw new GitException(sprintf('Version %s not found for %s/%s on %s.', $packageInput->version, $packageInput->vendor, $packageInput->package, $definedRemoteSource->host)); } } else @@ -279,7 +268,7 @@ if (!isset($releases[$selected_version])) { - throw new VersionNotFoundException(sprintf('No releases found for the given repository. (Selected version: %s)', $selected_version)); + throw new GitException(sprintf('Version %s not found for %s/%s on %s.', $packageInput->version, $packageInput->vendor, $packageInput->package, $definedRemoteSource->host)); } return $releases[$selected_version]; diff --git a/src/ncc/Classes/GitlabExtension/GitlabService.php b/src/ncc/Classes/GitlabExtension/GitlabService.php index 7f50908..cbb72f7 100644 --- a/src/ncc/Classes/GitlabExtension/GitlabService.php +++ b/src/ncc/Classes/GitlabExtension/GitlabService.php @@ -26,10 +26,8 @@ use ncc\Classes\HttpClient; use ncc\Exceptions\AuthenticationException; use ncc\Exceptions\GitException; - use ncc\Exceptions\MalformedJsonException; use ncc\Exceptions\NetworkException; use ncc\Exceptions\NotSupportedException; - use ncc\Exceptions\ResourceNotFoundException; use ncc\Interfaces\RepositorySourceInterface; use ncc\Objects\DefinedRemoteSource; use ncc\Objects\HttpRequest; @@ -51,7 +49,6 @@ * @return RepositoryQueryResults * @throws AuthenticationException * @throws GitException - * @throws MalformedJsonException * @throws NetworkException */ public static function getGitRepository(RemotePackageInput $packageInput, DefinedRemoteSource $definedRemoteSource, ?Entry $entry=null): RepositoryQueryResults @@ -93,9 +90,7 @@ * @return RepositoryQueryResults * @throws AuthenticationException * @throws GitException - * @throws MalformedJsonException * @throws NetworkException - * @throws ResourceNotFoundException */ public static function getRelease(RemotePackageInput $package_input, DefinedRemoteSource $defined_remote_source, ?Entry $entry = null): RepositoryQueryResults { @@ -103,7 +98,7 @@ if(count($releases) === 0) { - throw new ResourceNotFoundException(sprintf('No releases found for the repository %s/%s (selected version: %s)', $package_input->vendor, $package_input->package, $package_input->version)); + throw new GitException(sprintf('No releases found for the repository %s/%s (selected version: %s)', $package_input->vendor, $package_input->package, $package_input->version)); } // Query the latest package only @@ -148,7 +143,7 @@ if($selected_version === null) { - throw new ResourceNotFoundException(sprintf('Could not find a release for %s/%s with the version %s', $package_input->vendor, $package_input->package, $package_input->version)); + throw new GitException(sprintf('Could not find a release for %s/%s with the version %s', $package_input->vendor, $package_input->package, $package_input->version)); } } else @@ -158,7 +153,7 @@ if(!isset($releases[$selected_version])) { - throw new ResourceNotFoundException(sprintf('Could not find a release for %s/%s with the version %s', $package_input->vendor, $package_input->package, $package_input->version)); + throw new GitException(sprintf('Could not find a release for %s/%s with the version %s', $package_input->vendor, $package_input->package, $package_input->version)); } return $releases[$selected_version]; @@ -186,7 +181,6 @@ * @return array * @throws AuthenticationException * @throws GitException - * @throws MalformedJsonException * @throws NetworkException */ private static function getReleases(string $owner, string $repository, DefinedRemoteSource $definedRemoteSource, ?Entry $entry): array diff --git a/src/ncc/Classes/NccExtension/PackageCompiler.php b/src/ncc/Classes/NccExtension/PackageCompiler.php index cbd6bb6..9235023 100644 --- a/src/ncc/Classes/NccExtension/PackageCompiler.php +++ b/src/ncc/Classes/NccExtension/PackageCompiler.php @@ -34,10 +34,8 @@ use ncc\Exceptions\BuildException; use ncc\Exceptions\ConfigurationException; use ncc\Exceptions\IOException; - use ncc\Exceptions\MalformedJsonException; use ncc\Exceptions\NotSupportedException; use ncc\Exceptions\PathNotFoundException; - use ncc\Exceptions\RunnerExecutionException; use ncc\Interfaces\CompilerInterface; use ncc\Managers\ProjectManager; use ncc\ncc; @@ -60,7 +58,6 @@ * @throws BuildException * @throws ConfigurationException * @throws IOException - * @throws MalformedJsonException * @throws NotSupportedException * @throws PathNotFoundException */ @@ -154,8 +151,8 @@ * @param ProjectConfiguration $configuration * @return array * @throws IOException + * @throws NotSupportedException * @throws PathNotFoundException - * @throws RunnerExecutionException */ public static function compileExecutionPolicies(string $path, ProjectConfiguration $configuration): array { diff --git a/src/ncc/Classes/NccExtension/Runner.php b/src/ncc/Classes/NccExtension/Runner.php index de39aa3..ff16041 100644 --- a/src/ncc/Classes/NccExtension/Runner.php +++ b/src/ncc/Classes/NccExtension/Runner.php @@ -25,9 +25,9 @@ use ncc\Enums\Scopes; use ncc\Exceptions\AuthenticationException; use ncc\Exceptions\IOException; - use ncc\Exceptions\NoAvailableUnitsException; + use ncc\Exceptions\NotSupportedException; + use ncc\Exceptions\OperationException; use ncc\Exceptions\PathNotFoundException; - use ncc\Exceptions\RunnerExecutionException; use ncc\Managers\ExecutionPointerManager; use ncc\Objects\Package\ExecutionUnit; use ncc\Utilities\Resolver; @@ -43,9 +43,9 @@ * @return void * @throws AuthenticationException * @throws IOException - * @throws NoAvailableUnitsException + * @throws OperationException * @throws PathNotFoundException - * @throws RunnerExecutionException + * @throws NotSupportedException */ public static function temporaryExecute(string $package, string $version, ExecutionUnit $unit): void { diff --git a/src/ncc/Classes/PhpExtension/PhpCompiler.php b/src/ncc/Classes/PhpExtension/PhpCompiler.php index a46fc85..4e7fc57 100644 --- a/src/ncc/Classes/PhpExtension/PhpCompiler.php +++ b/src/ncc/Classes/PhpExtension/PhpCompiler.php @@ -35,10 +35,9 @@ use ncc\Exceptions\BuildException; use ncc\Exceptions\ConfigurationException; use ncc\Exceptions\IOException; + use ncc\Exceptions\OperationException; use ncc\Exceptions\PackageException; use ncc\Exceptions\PathNotFoundException; - use ncc\Exceptions\RunnerExecutionException; - use ncc\Exceptions\VersionNotFoundException; use ncc\Interfaces\CompilerInterface; use ncc\Managers\PackageLockManager; use ncc\Objects\Package; @@ -86,6 +85,7 @@ * @param string $build_configuration * @return void * @throws ConfigurationException + * @throws OperationException * @throws PackageException */ public function prepare(string $build_configuration=BuildConfigurationValues::DEFAULT): void @@ -279,7 +279,7 @@ $version = $package->getVersion($dependency->Version); if($version === null) { - throw new VersionNotFoundException('Cannot find version ' . $dependency->Version . ' for dependency ' . $dependency->Name); + throw new OperationException('Cannot find version ' . $dependency->Version . ' for dependency ' . $dependency->Name); } Console::outDebug(sprintf('copying shadow package %s=%s to %s', $dependency->Name, $dependency->Version, $out_path)); @@ -327,7 +327,6 @@ * @throws BuildException * @throws IOException * @throws PathNotFoundException - * @throws RunnerExecutionException */ public function build(): ?Package { @@ -469,7 +468,6 @@ * @return void * @throws IOException * @throws PathNotFoundException - * @throws RunnerExecutionException */ public function compileExecutionPolicies(): void { diff --git a/src/ncc/Enums/ExceptionCodes.php b/src/ncc/Enums/ExceptionCodes.php index 736c7ed..f433945 100644 --- a/src/ncc/Enums/ExceptionCodes.php +++ b/src/ncc/Enums/ExceptionCodes.php @@ -28,71 +28,26 @@ */ final class ExceptionCodes { - /** - * @see MalformedJsonException - */ - public const MALFORMED_JSON = -1705; - /** * @see RuntimeException */ public const RUNTIME = -1706; - /** - * @see ConstantReadonlyException - */ - public const CONSTANT_READ_ONLY = -1709; - - /** - * @see NoUnitsFoundException - */ - public const NO_UNITS_FOUND = -1715; - /** * @see BuildException */ public const BUILD_EXCEPTION = -1727; - /** - * @see InstallationException - */ - public const INSTALLATION_EXCEPTION = -1730; - /** * @see IOException */ public const IO_EXCEPTION = -1735; - /** - * @see VersionNotFoundException - */ - public const VERSION_NOT_FOUND = -1737; - - /** - * @see RunnerExecutionException - */ - public const RUNNER_EXECUTION_EXCEPTION = -1741; - - /** - * @see NoAvailableUnitsException - */ - public const NO_AVAILABLE_UNITS = -1742; - /** * @see ComposerException */ public const COMPOSER_EXCEPTION = -1749; - /** - * @see UserAbortedOperationException - */ - public const USER_ABORTED_OPERATION = -1750; - - /** - * @see ImportException - */ - public const IMPORT_EXCEPTION = -1757; - /** * @see AuthenticationException */ @@ -138,22 +93,19 @@ */ public const INTEGRITY_EXCEPTION = -1775; + /** + * @see OperationException + */ + public const OPERATION_EXCEPTION = -1776; + /** * All the exception codes from NCC */ public const All = [ - self::MALFORMED_JSON, self::RUNTIME, - self::CONSTANT_READ_ONLY, - self::NO_UNITS_FOUND, self::BUILD_EXCEPTION, - self::INSTALLATION_EXCEPTION, self::IO_EXCEPTION, - self::VERSION_NOT_FOUND, - self::RUNNER_EXECUTION_EXCEPTION, - self::NO_AVAILABLE_UNITS, self::COMPOSER_EXCEPTION, - self::USER_ABORTED_OPERATION, self::AUTHENTICATION_EXCEPTION, self::NOT_SUPPORTED_EXCEPTION, self::ARCHIVE_EXCEPTION, @@ -162,6 +114,7 @@ self::CONFIGURATION_EXCEPTION, self::PACKAGE_EXCEPTION, self::NETWORK_EXCEPTION, - self::INTEGRITY_EXCEPTION + self::INTEGRITY_EXCEPTION, + self::OPERATION_EXCEPTION ]; } \ No newline at end of file diff --git a/src/ncc/Exceptions/ComponentChecksumException.php b/src/ncc/Exceptions/ComponentChecksumException.php deleted file mode 100644 index 83eb02b..0000000 --- a/src/ncc/Exceptions/ComponentChecksumException.php +++ /dev/null @@ -1,40 +0,0 @@ - Python2Runner::getFileExtension(), Runners::PYTHON_3 => Python3Runner::getFileExtension(), Runners::LUA => LuaRunner::getFileExtension(), - default => throw new RunnerExecutionException('The runner \'' . $unit->execution_policy->runner . '\' is not supported'), + default => throw new NotSupportedException('The runner \'' . $unit->execution_policy->runner . '\' is not supported'), }; Console::outDebug(sprintf('bin_file=%s', $bin_file)); @@ -265,7 +266,9 @@ * @param string $version * @param string $name * @return bool + * @throws AuthenticationException * @throws IOException + * @throws PathNotFoundException */ public function removeUnit(string $package, string $version, string $name): bool { @@ -326,6 +329,7 @@ * @param string $version * @return array * @throws IOException + * @throws PathNotFoundException */ public function getUnits(string $package, string $version): array { @@ -363,8 +367,8 @@ * @param array $args * @return int * @throws IOException - * @throws NoAvailableUnitsException - * @throws RunnerExecutionException + * @throws OperationException + * @throws PathNotFoundException */ public function executeUnit(string $package, string $version, string $name, array $args=[]): int { @@ -375,7 +379,7 @@ if(!file_exists($package_config_path)) { - throw new NoAvailableUnitsException('There is no available units for \'' . $package . '=' .$version .'\''); + throw new OperationException('There is no available units for \'' . $package . '=' .$version .'\''); } $execution_pointers = ExecutionPointers::fromArray(ZiProto::decode(IO::fread($package_config_path))); @@ -383,7 +387,7 @@ if($unit === null) { - throw new RunnerExecutionException('The execution unit \'' . $name . '\' was not found for \'' . $package . '=' .$version .'\''); + throw new OperationException('The execution unit \'' . $name . '\' was not found for \'' . $package . '=' .$version .'\''); } Console::outDebug(sprintf('unit=%s', $unit->execution_policy->name)); @@ -453,7 +457,6 @@ } } - Console::outDebug(sprintf('working_directory=%s', $process->getWorkingDirectory())); Console::outDebug(sprintf('timeout=%s', (int)$process->getTimeout())); Console::outDebug(sprintf('silent=%s', ($unit->execution_policy->execute->silent ? 'true' : 'false'))); @@ -516,10 +519,11 @@ * @param Package $package * @param string $unit_name * @return void + * @throws AuthenticationException * @throws IOException - * @throws NoAvailableUnitsException + * @throws NotSupportedException + * @throws OperationException * @throws PathNotFoundException - * @throws RunnerExecutionException */ public function temporaryExecute(Package $package, string $unit_name): void { @@ -528,7 +532,7 @@ if($unit === null) { - throw new NoAvailableUnitsException(sprintf('No execution unit named \'%s\' is available for package \'%s\'', $unit_name, $package->assembly->package)); + throw new OperationException(sprintf('No execution unit named \'%s\' is available for package \'%s\'', $unit_name, $package->assembly->package)); } // Get the required units @@ -577,8 +581,8 @@ * @param Process|null $process * @return bool * @throws IOException - * @throws NoAvailableUnitsException - * @throws RunnerExecutionException + * @throws OperationException + * @throws PathNotFoundException */ public function handleExit(string $package, string $version, ExitHandle $exit_handler, ?Process $process=null): bool { diff --git a/src/ncc/Managers/PackageManager.php b/src/ncc/Managers/PackageManager.php index dead8c7..ebef9e7 100644 --- a/src/ncc/Managers/PackageManager.php +++ b/src/ncc/Managers/PackageManager.php @@ -39,13 +39,11 @@ use ncc\Classes\PhpExtension\PhpInstaller; use ncc\CLI\Main; use ncc\Exceptions\AuthenticationException; - use ncc\Exceptions\InstallationException; use ncc\Exceptions\IOException; use ncc\Exceptions\NotSupportedException; + use ncc\Exceptions\OperationException; use ncc\Exceptions\PackageException; use ncc\Exceptions\PathNotFoundException; - use ncc\Exceptions\RunnerExecutionException; - use ncc\Exceptions\VersionNotFoundException; use ncc\Objects\DefinedRemoteSource; use ncc\Objects\InstallationPaths; use ncc\Objects\Package; @@ -99,12 +97,10 @@ * @return string * @throws AuthenticationException * @throws IOException - * @throws InstallationException * @throws NotSupportedException + * @throws OperationException * @throws PackageException * @throws PathNotFoundException - * @throws RunnerExecutionException - * @throws VersionNotFoundException */ public function install(string $package_path, ?Entry $entry=null, array $options=[]): string { @@ -230,7 +226,7 @@ } catch(Exception $e) { - throw new InstallationException('Error while creating directory, ' . $e->getMessage(), $e); + throw new IOException('Error while creating directory, ' . $e->getMessage(), $e); } try @@ -245,7 +241,7 @@ } catch(Exception $e) { - throw new InstallationException('Cannot initialize package install, ' . $e->getMessage(), $e); + throw new OperationException('Cannot initialize package install, ' . $e->getMessage(), $e); } // Execute the pre-installation stage before the installation stage @@ -257,7 +253,7 @@ } catch (Exception $e) { - throw new InstallationException('Pre installation stage failed, ' . $e->getMessage(), $e); + throw new OperationException('Pre installation stage failed, ' . $e->getMessage(), $e); } if($package->installer?->PreInstall !== null && count($package->installer->PreInstall) > 0) @@ -301,7 +297,7 @@ } catch(Exception $e) { - throw new InstallationException('Cannot process one or more components, ' . $e->getMessage(), $e); + throw new OperationException('Cannot process one or more components, ' . $e->getMessage(), $e); } ++$current_steps; @@ -331,7 +327,7 @@ } catch(Exception $e) { - throw new InstallationException('Cannot process one or more resources, ' . $e->getMessage(), $e); + throw new OperationException('Cannot process one or more resources, ' . $e->getMessage(), $e); } ++$current_steps; @@ -367,7 +363,7 @@ { if($package->main_execution_policy === null) { - throw new InstallationException('Cannot create symlink, no main execution policy is defined'); + throw new OperationException('Cannot create symlink, no main execution policy is defined'); } Console::outDebug(sprintf('creating symlink to %s', $package->assembly->package)); @@ -388,7 +384,7 @@ } catch (Exception $e) { - throw new InstallationException('Post installation stage failed, ' . $e->getMessage(), $e); + throw new OperationException('Post installation stage failed, ' . $e->getMessage(), $e); } if($package->installer?->PostInstall !== null && count($package->installer->PostInstall) > 0) @@ -446,8 +442,8 @@ * @param string $source * @param Entry|null $entry * @return string - * @throws InstallationException * @throws NotSupportedException + * @throws OperationException * @throws PackageException */ public function fetchFromSource(string $source, ?Entry $entry=null): string @@ -498,7 +494,7 @@ $source = (new RemoteSourcesManager())->getRemoteSource($input->source); if($source === null) { - throw new InstallationException('Remote source ' . $input->source . ' is not defined'); + throw new OperationException('Remote source ' . $input->source . ' is not defined'); } $repositoryQueryResults = Functions::getRepositoryQueryResults($input, $source, $entry); @@ -613,7 +609,7 @@ * @param Entry|null $entry * @param array $options * @return string - * @throws InstallationException + * @throws OperationException */ public function installFromSource(string $source, ?Entry $entry, array $options=[]): string { @@ -626,7 +622,7 @@ } catch(Exception $e) { - throw new InstallationException('Cannot install package from source, ' . $e->getMessage(), $e); + throw new OperationException('Cannot install package from source, ' . $e->getMessage(), $e); } } @@ -639,12 +635,10 @@ * @return void * @throws AuthenticationException * @throws IOException - * @throws InstallationException * @throws NotSupportedException + * @throws OperationException * @throws PackageException * @throws PathNotFoundException - * @throws RunnerExecutionException - * @throws VersionNotFoundException */ private function processDependency(Dependency $dependency, Package $package, string $package_path, ?Entry $entry=null, array $options=[]): void { @@ -790,7 +784,7 @@ $version = $package->getVersion($exploded[1]); if($version === null) { - throw new VersionNotFoundException('Version ' . $exploded[1] . ' not found for package ' . $exploded[0]); + throw new OperationException('Version ' . $exploded[1] . ' not found for package ' . $exploded[0]); } foreach ($version->Dependencies as $dependency) @@ -872,6 +866,7 @@ * @throws AuthenticationException * @throws IOException * @throws PackageException + * @throws PathNotFoundException */ public function uninstallPackageVersion(string $package, string $version): void { @@ -987,7 +982,7 @@ /** * @param Package $package * @param InstallationPaths $paths - * @throws InstallationException + * @throws OperationException */ private static function initData(Package $package, InstallationPaths $paths): void { @@ -1020,7 +1015,7 @@ } catch (IOException $e) { - throw new InstallationException('Cannot write to file \'' . $file . '\', ' . $e->getMessage(), $e); + throw new OperationException('Cannot write to file \'' . $file . '\', ' . $e->getMessage(), $e); } } } diff --git a/src/ncc/Managers/ProjectManager.php b/src/ncc/Managers/ProjectManager.php index b3576da..c8b686d 100644 --- a/src/ncc/Managers/ProjectManager.php +++ b/src/ncc/Managers/ProjectManager.php @@ -31,7 +31,6 @@ use ncc\Exceptions\BuildException; use ncc\Exceptions\ConfigurationException; use ncc\Exceptions\IOException; - use ncc\Exceptions\MalformedJsonException; use ncc\Exceptions\NotSupportedException; use ncc\Exceptions\PathNotFoundException; use ncc\Objects\ProjectConfiguration; @@ -69,7 +68,6 @@ * @param string $path * @throws ConfigurationException * @throws IOException - * @throws MalformedJsonException * @throws PathNotFoundException */ public function __construct(string $path) @@ -105,7 +103,6 @@ * @param array $options * @throws ConfigurationException * @throws IOException - * @throws MalformedJsonException */ public function initializeProject(Compiler $compiler, string $name, string $package, ?string $src=null, array $options=[]): void { @@ -213,7 +210,6 @@ * @return void * @throws ConfigurationException * @throws IOException - * @throws MalformedJsonException * @throws PathNotFoundException */ public function load(): void @@ -230,7 +226,6 @@ * Saves the project configuration * * @return void - * @throws MalformedJsonException */ public function save(): void { @@ -248,7 +243,6 @@ * @return ProjectConfiguration * @throws ConfigurationException * @throws IOException - * @throws MalformedJsonException * @throws PathNotFoundException */ public function getProjectConfiguration(): ProjectConfiguration @@ -280,7 +274,6 @@ * @throws BuildException * @throws ConfigurationException * @throws IOException - * @throws MalformedJsonException * @throws NotSupportedException * @throws PathNotFoundException */ diff --git a/src/ncc/Objects/PackageLock.php b/src/ncc/Objects/PackageLock.php index 2d3b975..2f0e837 100644 --- a/src/ncc/Objects/PackageLock.php +++ b/src/ncc/Objects/PackageLock.php @@ -25,7 +25,7 @@ namespace ncc\Objects; use ncc\Enums\Versions; - use ncc\Exceptions\VersionNotFoundException; + use ncc\Exceptions\IOException; use ncc\Objects\PackageLock\PackageEntry; use ncc\Utilities\Console; use ncc\Utilities\Functions; @@ -183,7 +183,7 @@ { $version_entry = $package_entry->getVersion($version); } - catch (VersionNotFoundException $e) + catch (IOException $e) { unset($e); return false; diff --git a/src/ncc/Objects/ProjectConfiguration.php b/src/ncc/Objects/ProjectConfiguration.php index 849a869..3263e77 100644 --- a/src/ncc/Objects/ProjectConfiguration.php +++ b/src/ncc/Objects/ProjectConfiguration.php @@ -28,7 +28,6 @@ use ncc\Enums\Options\BuildConfigurationValues; use ncc\Exceptions\ConfigurationException; use ncc\Exceptions\IOException; - use ncc\Exceptions\MalformedJsonException; use ncc\Exceptions\NotSupportedException; use ncc\Exceptions\PathNotFoundException; use ncc\Interfaces\BytecodeObjectInterface; @@ -366,7 +365,6 @@ * @param string $path * @param bool $bytecode * @return void - * @throws MalformedJsonException * @noinspection PhpUnused */ public function toFile(string $path, bool $bytecode=false): void @@ -386,7 +384,6 @@ * @param string $path * @return ProjectConfiguration * @throws IOException - * @throws MalformedJsonException * @throws PathNotFoundException */ public static function fromFile(string $path): ProjectConfiguration diff --git a/src/ncc/Utilities/Functions.php b/src/ncc/Utilities/Functions.php index 5f65a65..bb28727 100644 --- a/src/ncc/Utilities/Functions.php +++ b/src/ncc/Utilities/Functions.php @@ -42,10 +42,9 @@ use ncc\Exceptions\ArchiveException; use ncc\Exceptions\AuthenticationException; use ncc\Exceptions\IOException; - use ncc\Exceptions\MalformedJsonException; use ncc\Exceptions\NetworkException; + use ncc\Exceptions\NotSupportedException; use ncc\Exceptions\PathNotFoundException; - use ncc\Exceptions\RunnerExecutionException; use ncc\Managers\ConfigurationManager; use ncc\Managers\CredentialManager; use ncc\Managers\PackageLockManager; @@ -121,7 +120,6 @@ * @param int $flags * @return mixed * @throws IOException - * @throws MalformedJsonException * @throws PathNotFoundException */ public static function loadJsonFile(string $path, int $flags=0): mixed @@ -140,7 +138,7 @@ * @param string $json * @param int $flags * @return mixed - * @throws MalformedJsonException + * @throws IOException */ public static function loadJson(string $json, int $flags=0): mixed { @@ -150,7 +148,7 @@ } catch(Throwable $e) { - throw new MalformedJsonException($e->getMessage(), $e); + throw new IOException($e->getMessage(), $e); } } @@ -160,7 +158,7 @@ * @param mixed $value * @param int $flags * @return string - * @throws MalformedJsonException + * @throws IOException */ public static function encodeJson(mixed $value, int $flags=0): string { @@ -175,7 +173,7 @@ } catch (JsonException $e) { - throw new MalformedJsonException($e->getMessage(), $e); + throw new IOException($e->getMessage(), $e); } } @@ -186,7 +184,6 @@ * @param string $path * @param int $flags * @return void - * @throws MalformedJsonException */ public static function encodeJsonFile(mixed $value, string $path, int $flags=0): void { @@ -291,8 +288,8 @@ * @param ExecutionPolicy $policy * @return ExecutionUnit * @throws IOException + * @throws NotSupportedException * @throws PathNotFoundException - * @throws RunnerExecutionException */ public static function compileRunner(string $path, ExecutionPolicy $policy): ExecutionUnit { @@ -305,7 +302,7 @@ Runners::PYTHON_2 => Python2Runner::processUnit($path, $policy), Runners::PYTHON_3 => Python3Runner::processUnit($path, $policy), Runners::LUA => LuaRunner::processUnit($path, $policy), - default => throw new RunnerExecutionException('The runner \'' . $policy->runner . '\' is not supported'), + default => throw new NotSupportedException('The runner \'' . $policy->runner . '\' is not supported'), }; } @@ -419,7 +416,6 @@ * @param string $path * @return ComposerJson * @throws IOException - * @throws MalformedJsonException * @throws PathNotFoundException */ public static function loadComposerJson(string $path): ComposerJson @@ -432,7 +428,7 @@ } catch(JsonException $e) { - throw new MalformedJsonException('Cannot parse composer.json, ' . $e->getMessage(), $e); + throw new IOException('Cannot parse composer.json, ' . $e->getMessage(), $e); } } diff --git a/src/ncc/Utilities/PathFinder.php b/src/ncc/Utilities/PathFinder.php index 21bc5a4..f501949 100644 --- a/src/ncc/Utilities/PathFinder.php +++ b/src/ncc/Utilities/PathFinder.php @@ -25,7 +25,7 @@ use InvalidArgumentException; use ncc\Enums\Scopes; use ncc\Exceptions\ConfigurationException; - use ncc\Exceptions\RunnerExecutionException; + use ncc\Exceptions\OperationException; use ncc\ThirdParty\Symfony\Process\ExecutableFinder; class PathFinder @@ -219,7 +219,7 @@ * * @param string $runner * @return string - * @throws RunnerExecutionException + * @throws OperationException */ public static function findRunner(string $runner): string { @@ -242,6 +242,6 @@ return $exec_path; } - throw new RunnerExecutionException(sprintf('Unable to find \'%s\' executable', $runner)); + throw new OperationException(sprintf('Unable to find \'%s\' executable', $runner)); } } \ No newline at end of file diff --git a/src/ncc/ncc.php b/src/ncc/ncc.php index 24c3051..2808983 100644 --- a/src/ncc/ncc.php +++ b/src/ncc/ncc.php @@ -26,10 +26,10 @@ namespace ncc; use ncc\Exceptions\IOException; - use ncc\Exceptions\MalformedJsonException; use ncc\Exceptions\PathNotFoundException; use ncc\Objects\NccVersionInformation; use ncc\Utilities\Functions; + use RuntimeException; /** * @author Zi Xing Narrakas @@ -50,7 +50,6 @@ * * @param boolean $reload Indicates if the cached version is to be ignored and the version file to be reloaded and validated * @return NccVersionInformation - * @throws IOException * @throws PathNotFoundException */ public static function getVersionInformation(bool $reload=False): NccVersionInformation @@ -62,26 +61,26 @@ if(!file_exists(__DIR__ . DIRECTORY_SEPARATOR . 'version.json')) { - throw new \RuntimeException('The file \'version.json\' was not found in \'' . __DIR__ . '\''); + throw new RuntimeException('The file \'version.json\' was not found in \'' . __DIR__ . '\''); } try { self::$version_information = NccVersionInformation::fromArray(Functions::loadJsonFile(__DIR__ . DIRECTORY_SEPARATOR . 'version.json', Functions::FORCE_ARRAY)); } - catch(MalformedJsonException $e) + catch(IOException $e) { - throw new \RuntimeException('Unable to parse JSON contents of \'version.json\' in \'' . __DIR__ . '\'', $e); + throw new RuntimeException('Unable to parse JSON contents of \'version.json\' in \'' . __DIR__ . '\'', $e); } if(self::$version_information->Version === null) { - throw new \RuntimeException('The version number is not specified in the version information file'); + throw new RuntimeException('The version number is not specified in the version information file'); } if(self::$version_information->Branch === null) { - throw new \RuntimeException('The version branch is not specified in the version information file'); + throw new RuntimeException('The version branch is not specified in the version information file'); } return self::$version_information; @@ -136,7 +135,7 @@ if(!defined('NCC_INIT')) { /** @noinspection ClassConstantCanBeUsedInspection */ - throw new \RuntimeException('NCC Must be initialized before executing ' . get_called_class() . '::getConstants()'); + throw new RuntimeException('NCC Must be initialized before executing ' . get_called_class() . '::getConstants()'); } return [