diff --git a/CHANGELOG.md b/CHANGELOG.md index 87f28bc..1acf8b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -121,6 +121,11 @@ features. - Removed unused exception `GitCheckoutException` in `\ncc\Exceptions` in favor of `GitException` - Removed unused exception `GithubServiceException` in `\ncc\Exceptions` in favor of `GitException` - Removed unused exception `GitTagsException` in `\ncc\Exceptions` in favor of `GitException` + - Removed unused exception `GitlabServiceException` in `\ncc\Exceptions` in favor of `GitException` + - Removed unused exception `UnsupportedArchiveException` in `\ncc\Exceptions` in favor of `ArchiveException` + - Removed unused exception `NotImplementedException` in `\ncc\Exceptions` in favor of `NotSupportedException` + - Removed unused exception `UnsupportedCompilerExtensionException` in `\ncc\Exceptions` in favor of `NotSupportedException` + - Removed unused exception `UnsupportedExtensionVersionException` in `\ncc\Exceptions` (not used) diff --git a/scratch/exceptions_plan.txt b/scratch/exceptions_plan.txt index 901aee0..8e162ac 100644 --- a/scratch/exceptions_plan.txt +++ b/scratch/exceptions_plan.txt @@ -55,17 +55,17 @@ GitException * GIT_CLONE_EXCEPTION * GIT_CHECKOUT_EXCEPTION * GITHUB_SERVICE_EXCEPTION - GITLAB_SERVICE_EXCEPTION + * GITLAB_SERVICE_EXCEPTION * GIT_TAGS_EXCEPTION ArchiveException - UNSUPPORTED_ARCHIVE - ARCHIVE_EXCEPTION + * UNSUPPORTED_ARCHIVE + * ARCHIVE_EXCEPTION NotSupportedException - NOT_IMPLEMENTED - UNSUPPORTED_COMPILER_EXTENSION - UNSUPPORTED_EXTENSION_VERSION + * NOT_IMPLEMENTED + * UNSUPPORTED_COMPILER_EXTENSION + * UNSUPPORTED_EXTENSION_VERSION UNSUPPORTED_COMPONENT_TYPE NOT_SUPPORTED_EXCEPTION UNSUPPORTED_PROJECT_TYPE diff --git a/src/ncc/Classes/ComposerExtension/ComposerSourceBuiltin.php b/src/ncc/Classes/ComposerExtension/ComposerSourceBuiltin.php index 061bb9c..d4aba9a 100644 --- a/src/ncc/Classes/ComposerExtension/ComposerSourceBuiltin.php +++ b/src/ncc/Classes/ComposerExtension/ComposerSourceBuiltin.php @@ -40,14 +40,12 @@ namespace ncc\Classes\ComposerExtension; use ncc\Exceptions\ComposerNotAvailableException; use ncc\Exceptions\PathNotFoundException; use ncc\Exceptions\InternalComposerNotAvailableException; - use ncc\Exceptions\InvalidScopeException; use ncc\Exceptions\IOException; use ncc\Exceptions\MalformedJsonException; use ncc\Exceptions\PackageNotFoundException; use ncc\Exceptions\PackagePreparationFailedException; use ncc\Exceptions\ProjectConfigurationNotFoundException; use ncc\Exceptions\RuntimeException; - use ncc\Exceptions\UnsupportedCompilerExtensionException; use ncc\Exceptions\UserAbortedOperationException; use ncc\Interfaces\ServiceSourceInterface; use ncc\Managers\ProjectManager; @@ -89,14 +87,12 @@ namespace ncc\Classes\ComposerExtension; * @throws ComposerNotAvailableException * @throws IOException * @throws InternalComposerNotAvailableException - * @throws InvalidScopeException * @throws MalformedJsonException * @throws PackageNotFoundException * @throws PackagePreparationFailedException * @throws PathNotFoundException * @throws ProjectConfigurationNotFoundException * @throws RuntimeException - * @throws UnsupportedCompilerExtensionException * @throws UserAbortedOperationException */ public static function fetch(RemotePackageInput $packageInput): string @@ -136,7 +132,6 @@ namespace ncc\Classes\ComposerExtension; * @throws PackagePreparationFailedException * @throws PathNotFoundException * @throws ProjectConfigurationNotFoundException - * @throws UnsupportedCompilerExtensionException * @throws UserAbortedOperationException */ public static function fromLocal(string $path): string @@ -208,7 +203,6 @@ namespace ncc\Classes\ComposerExtension; * @throws PackagePreparationFailedException * @throws PathNotFoundException * @throws ProjectConfigurationNotFoundException - * @throws UnsupportedCompilerExtensionException */ private static function compilePackages(string $composer_lock_path): array { @@ -529,21 +523,19 @@ namespace ncc\Classes\ComposerExtension; * @param string $package * @param string|null $version * @return string - * @throws AccessDeniedException * @throws ComposerDisabledException * @throws ComposerException * @throws ComposerNotAvailableException - * @throws PathNotFoundException * @throws IOException * @throws InternalComposerNotAvailableException - * @throws InvalidScopeException + * @throws PathNotFoundException * @throws UserAbortedOperationException */ private static function require(string $vendor, string $package, ?string $version = null): string { if (Resolver::resolveScope() !== Scopes::SYSTEM) { - throw new AccessDeniedException('Insufficient permissions to require'); + throw new \RuntimeException('Cannot require a package with insufficient permissions'); } if ($version === null) @@ -693,10 +685,10 @@ namespace ncc\Classes\ComposerExtension; * @param array $version_map * @param mixed $composer_package * @return ProjectConfiguration - * @throws AccessDeniedException * @throws IOException * @throws MalformedJsonException * @throws PackagePreparationFailedException + * @throws PathNotFoundException */ private static function convertProject(string $package_path, array $version_map, ?ComposerJson $composer_package=null): ProjectConfiguration { diff --git a/src/ncc/Classes/GithubExtension/GithubService.php b/src/ncc/Classes/GithubExtension/GithubService.php index 746d387..0e01bfe 100644 --- a/src/ncc/Classes/GithubExtension/GithubService.php +++ b/src/ncc/Classes/GithubExtension/GithubService.php @@ -27,7 +27,6 @@ use ncc\Classes\HttpClient; use ncc\Exceptions\AuthenticationException; use ncc\Exceptions\GitException; - use ncc\Exceptions\GitlabServiceException; use ncc\Exceptions\HttpException; use ncc\Exceptions\MalformedJsonException; use ncc\Exceptions\VersionNotFoundException; @@ -51,7 +50,6 @@ * @return RepositoryQueryResults * @throws AuthenticationException * @throws GitException - * @throws GitlabServiceException * @throws HttpException * @throws MalformedJsonException */ @@ -78,20 +76,19 @@ /** * Returns the download URL of the requested version of the package. * - * @param RemotePackageInput $packageInput - * @param DefinedRemoteSource $definedRemoteSource + * @param RemotePackageInput $package_input + * @param DefinedRemoteSource $defined_remote_source * @param Entry|null $entry * @return RepositoryQueryResults * @throws AuthenticationException * @throws GitException - * @throws GitlabServiceException * @throws HttpException * @throws MalformedJsonException * @throws VersionNotFoundException */ - public static function getRelease(RemotePackageInput $packageInput, DefinedRemoteSource $definedRemoteSource, ?Entry $entry = null): RepositoryQueryResults + public static function getRelease(RemotePackageInput $package_input, DefinedRemoteSource $defined_remote_source, ?Entry $entry = null): RepositoryQueryResults { - return self::processReleases($packageInput, $definedRemoteSource, $entry); + return self::processReleases($package_input, $defined_remote_source, $entry); } /** @@ -101,7 +98,6 @@ * @return RepositoryQueryResults * @throws AuthenticationException * @throws GitException - * @throws GitlabServiceException * @throws HttpException * @throws MalformedJsonException * @throws VersionNotFoundException @@ -120,7 +116,6 @@ * @return array * @throws AuthenticationException * @throws GitException - * @throws GitlabServiceException * @throws HttpException * @throws MalformedJsonException */ @@ -195,7 +190,6 @@ * @throws GitException * @throws HttpException * @throws MalformedJsonException - * @throws GitlabServiceException */ private static function getJsonResponse(HttpRequest $httpRequest, ?Entry $entry): array { @@ -221,7 +215,6 @@ * @return mixed * @throws AuthenticationException * @throws GitException - * @throws GitlabServiceException * @throws HttpException * @throws MalformedJsonException * @throws VersionNotFoundException diff --git a/src/ncc/Classes/GitlabExtension/GitlabService.php b/src/ncc/Classes/GitlabExtension/GitlabService.php index a545629..9aee83d 100644 --- a/src/ncc/Classes/GitlabExtension/GitlabService.php +++ b/src/ncc/Classes/GitlabExtension/GitlabService.php @@ -1,35 +1,35 @@ StatusCode !== 200) { - throw new GitlabServiceException(sprintf('Failed to fetch releases for the given repository. Status code: %s', $response->StatusCode)); - + throw new GitException(sprintf('Failed to fetch releases for the given repository. Status code: %s', $response->StatusCode)); } $response_decoded = Functions::loadJson($response->Body, Functions::FORCE_ARRAY); @@ -88,27 +87,27 @@ /** * Returns the download URL of the requested version of the package. * - * @param RemotePackageInput $packageInput - * @param DefinedRemoteSource $definedRemoteSource + * @param RemotePackageInput $package_input + * @param DefinedRemoteSource $defined_remote_source * @param Entry|null $entry * @return RepositoryQueryResults * @throws AuthenticationException - * @throws GitlabServiceException + * @throws GitException * @throws HttpException * @throws MalformedJsonException - * @throws VersionNotFoundException + * @throws ResourceNotFoundException */ - public static function getRelease(RemotePackageInput $packageInput, DefinedRemoteSource $definedRemoteSource, ?Entry $entry = null): RepositoryQueryResults + public static function getRelease(RemotePackageInput $package_input, DefinedRemoteSource $defined_remote_source, ?Entry $entry = null): RepositoryQueryResults { - $releases = self::getReleases($packageInput->vendor, $packageInput->package, $definedRemoteSource, $entry); + $releases = self::getReleases($package_input->vendor, $package_input->package, $defined_remote_source, $entry); if(count($releases) === 0) { - throw new VersionNotFoundException('No releases found for the given repository.'); + throw new ResourceNotFoundException(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 - if($packageInput->version === Versions::LATEST) + if($package_input->version === Versions::LATEST) { $latest_version = null; foreach($releases as $release) @@ -129,7 +128,7 @@ } // Query a specific version - if(!isset($releases[$packageInput->version])) + if(!isset($releases[$package_input->version])) { // Find the closest thing to the requested version $selected_version = null; @@ -141,7 +140,7 @@ continue; } - if(VersionComparator::compareVersion($version, $packageInput->version) === 1) + if(VersionComparator::compareVersion($version, $package_input->version) === 1) { $selected_version = $version; } @@ -149,18 +148,17 @@ if($selected_version === null) { - throw new VersionNotFoundException('No releases found for the given repository.'); + 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)); } } else { - $selected_version = $packageInput->version; + $selected_version = $package_input->version; } if(!isset($releases[$selected_version])) { - throw new VersionNotFoundException(sprintf('No releases found for the given repository. (Selected version: %s)', $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)); } return $releases[$selected_version]; @@ -187,7 +185,7 @@ * @param Entry|null $entry * @return array * @throws AuthenticationException - * @throws GitlabServiceException + * @throws GitException * @throws HttpException * @throws MalformedJsonException */ @@ -207,7 +205,7 @@ if($response->StatusCode !== 200) { - throw new GitlabServiceException(sprintf('Failed to fetch releases for the given repository. Status code: %s', $response->StatusCode)); + throw new GitException(sprintf('Failed to fetch releases for repository %s/%s. Status code: %s', $owner, $repository, $response->StatusCode)); } $response_decoded = Functions::loadJson($response->Body, Functions::FORCE_ARRAY); diff --git a/src/ncc/Classes/NccExtension/PackageCompiler.php b/src/ncc/Classes/NccExtension/PackageCompiler.php index 5ae5168..c3de69a 100644 --- a/src/ncc/Classes/NccExtension/PackageCompiler.php +++ b/src/ncc/Classes/NccExtension/PackageCompiler.php @@ -36,10 +36,10 @@ use ncc\Exceptions\BuildException; use ncc\Exceptions\IOException; use ncc\Exceptions\MalformedJsonException; + use ncc\Exceptions\NotSupportedException; use ncc\Exceptions\PathNotFoundException; use ncc\Exceptions\ProjectConfigurationNotFoundException; use ncc\Exceptions\RunnerExecutionException; - use ncc\Exceptions\UnsupportedCompilerExtensionException; use ncc\Exceptions\UnsupportedProjectTypeException; use ncc\Interfaces\CompilerInterface; use ncc\Managers\ProjectManager; @@ -65,9 +65,9 @@ * @throws BuildException * @throws IOException * @throws MalformedJsonException - * @throws ProjectConfigurationNotFoundException - * @throws UnsupportedCompilerExtensionException + * @throws NotSupportedException * @throws PathNotFoundException + * @throws ProjectConfigurationNotFoundException */ public static function compile(ProjectManager $manager, string $build_configuration=BuildConfigurationValues::DEFAULT): string { @@ -93,7 +93,7 @@ } else { - throw new UnsupportedCompilerExtensionException('The compiler extension \'' . $configuration->project->compiler->extension . '\' is not supported'); + throw new NotSupportedException('The compiler extension \'' . $configuration->project->compiler->extension . '\' is not supported'); } $build_configuration = $configuration->build->getBuildConfiguration($build_configuration)->name; diff --git a/src/ncc/Enums/ExceptionCodes.php b/src/ncc/Enums/ExceptionCodes.php index 4bcb0c7..98ea0ad 100644 --- a/src/ncc/Enums/ExceptionCodes.php +++ b/src/ncc/Enums/ExceptionCodes.php @@ -1,32 +1,26 @@ new PhpInstaller($package), - default => throw new UnsupportedCompilerExtensionException('The compiler extension \'' . $extension . '\' is not supported'), + default => throw new NotSupportedException(sprintf('Compiler extension %s is not supported with ncc', $extension)) }; if($this->getPackageVersion($package->assembly->package, $package->assembly->version) !== null) @@ -440,6 +438,7 @@ if($sources_manager->getRemoteSource($package->header->UpdateSource->repository->name) === null) { Console::outVerbose('Adding remote source ' . $package->header->UpdateSource->repository->name); + $defined_remote_source = new DefinedRemoteSource(); $defined_remote_source->name = $package->header->UpdateSource->repository->name; $defined_remote_source->host = $package->header->UpdateSource->repository->host; @@ -463,7 +462,7 @@ * @param Entry|null $entry * @return string * @throws InstallationException - * @throws NotImplementedException + * @throws NotSupportedException * @throws PackageFetchException */ public function fetchFromSource(string $source, ?Entry $entry=null): string @@ -504,7 +503,7 @@ } } - throw new NotImplementedException('Builtin source type ' . $input->source . ' is not implemented'); + throw new NotSupportedException(sprintf('Builtin source %s is not supported', $input->source)); } if($remote_source_type === RemoteSourceType::DEFINED) @@ -659,7 +658,7 @@ * @throws InvalidPackageNameException * @throws InvalidScopeException * @throws MissingDependencyException - * @throws NotImplementedException + * @throws NotSupportedException * @throws PackageAlreadyInstalledException * @throws PackageLockException * @throws PackageNotFoundException @@ -667,9 +666,7 @@ * @throws PathNotFoundException * @throws RunnerExecutionException * @throws SymlinkException - * @throws UnsupportedCompilerExtensionException * @throws VersionNotFoundException - * @throws PathNotFoundException */ private function processDependency(Dependency $dependency, Package $package, string $package_path, ?Entry $entry=null, array $options=[]): void { @@ -728,12 +725,12 @@ break; default: - throw new NotImplementedException('Dependency source type ' . $dependency->source_type . ' is not implemented'); + throw new NotSupportedException(sprintf('Dependency source type %s is not supported', $dependency->source_type)); } } elseif(!$dependency_met) { - throw new MissingDependencyException(sprintf('The dependency %s=%s for %s=%s is not met', $dependency->name, $dependency->version, $package->assembly->package, $package->assembly->version)); + throw new PackageNotFoundException(sprintf('Required dependency %s=%s is not installed', $dependency->name, $dependency->version)); } } diff --git a/src/ncc/Managers/ProjectManager.php b/src/ncc/Managers/ProjectManager.php index 0b1c9f2..988b957 100644 --- a/src/ncc/Managers/ProjectManager.php +++ b/src/ncc/Managers/ProjectManager.php @@ -35,11 +35,9 @@ use ncc\Exceptions\InvalidProjectNameException; use ncc\Exceptions\IOException; use ncc\Exceptions\MalformedJsonException; - use ncc\Exceptions\PackagePreparationFailedException; use ncc\Exceptions\PathNotFoundException; use ncc\Exceptions\ProjectAlreadyExistsException; use ncc\Exceptions\ProjectConfigurationNotFoundException; - use ncc\Exceptions\UnsupportedCompilerExtensionException; use ncc\Objects\ProjectConfiguration; use ncc\Objects\ProjectConfiguration\Compiler; use ncc\ThirdParty\Symfony\Uid\Uuid; @@ -294,7 +292,6 @@ * @throws MalformedJsonException * @throws PathNotFoundException * @throws ProjectConfigurationNotFoundException - * @throws UnsupportedCompilerExtensionException */ public function build(string $build_configuration=BuildConfigurationValues::DEFAULT): string { diff --git a/src/ncc/Objects/ProjectConfiguration.php b/src/ncc/Objects/ProjectConfiguration.php index 81b6ac1..81a4828 100644 --- a/src/ncc/Objects/ProjectConfiguration.php +++ b/src/ncc/Objects/ProjectConfiguration.php @@ -26,7 +26,6 @@ use Exception; use ncc\Enums\Options\BuildConfigurationValues; - use ncc\Exceptions\AccessDeniedException; use ncc\Exceptions\BuildConfigurationNotFoundException; use ncc\Exceptions\InvalidBuildConfigurationException; use ncc\Exceptions\InvalidConstantNameException; @@ -38,8 +37,6 @@ use ncc\Exceptions\PathNotFoundException; use ncc\Exceptions\RuntimeException; use ncc\Exceptions\UndefinedExecutionPolicyException; - use ncc\Exceptions\UnsupportedCompilerExtensionException; - use ncc\Exceptions\UnsupportedExtensionVersionException; use ncc\Interfaces\BytecodeObjectInterface; use ncc\Objects\ProjectConfiguration\Assembly; use ncc\Objects\ProjectConfiguration\Build; @@ -113,8 +110,6 @@ * @throws InvalidPropertyValueException * @throws RuntimeException * @throws UndefinedExecutionPolicyException - * @throws UnsupportedCompilerExtensionException - * @throws UnsupportedExtensionVersionException * @throws InvalidBuildConfigurationException */ public function validate(bool $throw_exception=True): bool @@ -403,7 +398,6 @@ * * @param string $path * @return ProjectConfiguration - * @throws AccessDeniedException * @throws IOException * @throws MalformedJsonException * @throws PathNotFoundException diff --git a/src/ncc/Objects/ProjectConfiguration/Compiler.php b/src/ncc/Objects/ProjectConfiguration/Compiler.php index 9420929..00de50b 100644 --- a/src/ncc/Objects/ProjectConfiguration/Compiler.php +++ b/src/ncc/Objects/ProjectConfiguration/Compiler.php @@ -29,9 +29,8 @@ use ncc\Enums\CompilerExtensionSupportedVersions; use ncc\Exceptions\InvalidPropertyValueException; use ncc\Exceptions\InvalidVersionConfigurationException; + use ncc\Exceptions\NotSupportedException; use ncc\Exceptions\RuntimeException; - use ncc\Exceptions\UnsupportedCompilerExtensionException; - use ncc\Exceptions\UnsupportedExtensionVersionException; use ncc\Interfaces\BytecodeObjectInterface; use ncc\ThirdParty\jelix\Version\VersionComparator; use ncc\Utilities\Functions; @@ -69,9 +68,8 @@ * @param bool $throw_exception * @return bool * @throws InvalidPropertyValueException + * @throws NotSupportedException * @throws RuntimeException - * @throws UnsupportedCompilerExtensionException - * @throws UnsupportedExtensionVersionException */ public function validate(bool $throw_exception=True): bool { @@ -126,7 +124,7 @@ { if($throw_exception) { - throw new UnsupportedCompilerExtensionException('The compiler extension \'' . $this->extension . '\' is not supported'); + throw new NotSupportedException('The compiler extension \'' . $this->extension . '\' is not supported'); } return False; @@ -139,7 +137,7 @@ { if($throw_exception) { - throw new UnsupportedExtensionVersionException('The MaximumVersion does not support version ' . $this->maximum_version . ' for the extension ' . $this->extension); + throw new NotSupportedException('The MaximumVersion does not support version ' . $this->maximum_version . ' for the extension ' . $this->extension); } return False; } @@ -148,14 +146,14 @@ { if($throw_exception) { - throw new UnsupportedExtensionVersionException('The MinimumVersion does not support version ' . $this->minimum_version . ' for the extension ' . $this->extension); + throw new NotSupportedException('The MinimumVersion does not support version ' . $this->minimum_version . ' for the extension ' . $this->extension); } return False; } break; default: - throw new UnsupportedCompilerExtensionException('The compiler extension \'' . $this->extension . '\' is not supported'); + throw new NotSupportedException('The compiler extension \'' . $this->extension . '\' is not supported'); } return True; diff --git a/src/ncc/Objects/ProjectConfiguration/Project.php b/src/ncc/Objects/ProjectConfiguration/Project.php index c2f2427..f52d7ad 100644 --- a/src/ncc/Objects/ProjectConfiguration/Project.php +++ b/src/ncc/Objects/ProjectConfiguration/Project.php @@ -26,8 +26,6 @@ use ncc\Exceptions\InvalidPropertyValueException; use ncc\Exceptions\RuntimeException; - use ncc\Exceptions\UnsupportedCompilerExtensionException; - use ncc\Exceptions\UnsupportedExtensionVersionException; use ncc\Interfaces\BytecodeObjectInterface; use ncc\Utilities\Functions; @@ -68,8 +66,6 @@ * @return bool * @throws InvalidPropertyValueException * @throws RuntimeException - * @throws UnsupportedCompilerExtensionException - * @throws UnsupportedExtensionVersionException */ public function validate(bool $throw_exception=True): bool { diff --git a/src/ncc/Runtime.php b/src/ncc/Runtime.php index da020d4..6e288d3 100644 --- a/src/ncc/Runtime.php +++ b/src/ncc/Runtime.php @@ -1,24 +1,24 @@ getLatestVersion(); + $version = $package_entry?->getLatestVersion(); } try @@ -119,7 +119,7 @@ if($version_entry === null) { - throw new VersionNotFoundException(); + throw new ImportException(sprintf('Version %s of %s is not installed', $version, $package)); } } catch (VersionNotFoundException $e) diff --git a/src/ncc/Utilities/Functions.php b/src/ncc/Utilities/Functions.php index 31d7c04..b870fe3 100644 --- a/src/ncc/Utilities/Functions.php +++ b/src/ncc/Utilities/Functions.php @@ -42,13 +42,11 @@ use ncc\Exceptions\AccessDeniedException; use ncc\Exceptions\ArchiveException; use ncc\Exceptions\AuthenticationException; - use ncc\Exceptions\GitlabServiceException; use ncc\Exceptions\HttpException; use ncc\Exceptions\IOException; use ncc\Exceptions\MalformedJsonException; use ncc\Exceptions\PathNotFoundException; use ncc\Exceptions\RunnerExecutionException; - use ncc\Exceptions\UnsupportedArchiveException; use ncc\Managers\ConfigurationManager; use ncc\Managers\CredentialManager; use ncc\Managers\PackageLockManager; @@ -123,7 +121,6 @@ * @param string $path * @param int $flags * @return mixed - * @throws AccessDeniedException * @throws IOException * @throws MalformedJsonException * @throws PathNotFoundException @@ -231,8 +228,8 @@ * @param string $copyright * @param bool $basic_ascii * @return string - * @throws AccessDeniedException * @throws IOException + * @throws PathNotFoundException */ public static function getBanner(string $version, string $copyright, bool $basic_ascii=false): string { @@ -424,9 +421,9 @@ * * @param string $path * @return ComposerJson - * @throws AccessDeniedException * @throws IOException * @throws MalformedJsonException + * @throws PathNotFoundException */ public static function loadComposerJson(string $path): ComposerJson { @@ -568,7 +565,6 @@ * @param bool $expect_json * @return HttpRequest * @throws AuthenticationException - * @throws GitlabServiceException */ public static function prepareGitServiceRequest(HttpRequest $http_request, ?Entry $entry=null, bool $expect_json=true): HttpRequest { @@ -576,7 +572,7 @@ { if(!$entry->isCurrentlyDecrypted()) { - throw new GitlabServiceException('The given Vault entry is not decrypted.'); + throw new RuntimeException('The given Vault entry is not decrypted.'); } switch ($entry->getPassword()?->getAuthenticationType()) @@ -586,7 +582,7 @@ break; case AuthenticationType::USERNAME_PASSWORD: - throw new AuthenticationException('Username/Password authentication is not supported'); + throw new AuthenticationException(sprintf('The given Vault entry is using the %s authentication type, which is not supported for Gitlab', AuthenticationType::USERNAME_PASSWORD)); } } @@ -606,7 +602,6 @@ * @param Entry|null $entry * @return string * @throws AuthenticationException - * @throws GitlabServiceException * @throws HttpException */ public static function downloadGitServiceFile(string $url, ?Entry $entry=null): string @@ -633,7 +628,6 @@ * @param string $path * @return string|null * @throws ArchiveException - * @throws UnsupportedArchiveException */ public static function extractArchive(string $path): ?string { @@ -650,12 +644,12 @@ RuntimeCache::setFileAsTemporary($out_path); - $mimeType = mime_content_type($path); - $supportedTypes = []; + $mime_type = mime_content_type($path); + $supported_types = []; if($unzip_executable !== null) { - $supportedTypes = array_merge($supportedTypes, [ + $supported_types = array_merge($supported_types, [ 'application/zip', 'application/x-zip', 'application/x-zip-compressed', @@ -673,7 +667,7 @@ if($tar_executable !== null) { - $supportedTypes = array_merge($supportedTypes, [ + $supported_types = array_merge($supported_types, [ 'application/x-tar', 'application/x-gzip', 'application/x-bzip2', @@ -686,17 +680,17 @@ RuntimeCache::set('warning_tar_shown', true); } - if(!in_array($mimeType, $supportedTypes, true)) + if(!in_array($mime_type, $supported_types, true)) { - throw new UnsupportedArchiveException("Unsupported archive type: $mimeType"); + throw new ArchiveException(sprintf('Cannot extract archive %s, unsupported archive type %s', $path, $mime_type)); } - $command = match ($mimeType) { + $command = match ($mime_type) { 'application/zip' => [$unzip_executable, $path, '-d', $out_path], 'application/x-tar' => [$tar_executable, '--verbose', '-xf', $path, '-C', $out_path], 'application/x-gzip' => [$tar_executable, '--verbose', '-xzf', $path, '-C', $out_path], 'application/x-bzip2' => [$tar_executable, '--verbose', '-xjf', $path, '-C', $out_path], - default => throw new UnsupportedArchiveException("Unsupported archive type: $mimeType"), + default => throw new ArchiveException(sprintf('Cannot extract archive %s, unsupported archive type %s', $path, $mime_type)), }; Console::out("Extracting archive $path"); diff --git a/src/ncc/Utilities/IO.php b/src/ncc/Utilities/IO.php index db05339..334a538 100644 --- a/src/ncc/Utilities/IO.php +++ b/src/ncc/Utilities/IO.php @@ -22,7 +22,6 @@ namespace ncc\Utilities; - use ncc\Exceptions\AccessDeniedException; use ncc\Exceptions\IOException; use ncc\Exceptions\PathNotFoundException; use SplFileInfo; @@ -81,7 +80,6 @@ * @param string $mode * @param int|null $length * @return string - * @throws AccessDeniedException * @throws IOException * @throws PathNotFoundException */ @@ -101,7 +99,7 @@ if(!is_readable($uri)) { - throw new AccessDeniedException(sprintf('Unable to read file: (%s)', $uri)); + throw new IOException(sprintf('Unable to read file (permission issue?): (%s)', $uri)); } $file = new SplFileObject($uri, $mode);