Updated exception handling in PackageReader
Optimized exception handling in PackageReader class by replacing NotSupportedException with IntegrityException. The update aligns with the objective of more accurate error handling and reporting during ZiProto decoding. The new IntegrityException provides a detailed error message, facilitating easier debugging.
This commit is contained in:
parent
27baeca112
commit
a2cd98ba98
2 changed files with 114 additions and 19 deletions
|
@ -12,6 +12,7 @@ This update introduces minor bug fixes.
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
- Update progress bar text to display basename only
|
- Update progress bar text to display basename only
|
||||||
|
- Updated exception handling in PackageReader
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- Improve build efficiency by preventing duplicate merges
|
- Improve build efficiency by preventing duplicate merges
|
||||||
|
|
|
@ -29,8 +29,8 @@
|
||||||
use ncc\Enums\Flags\PackageFlags;
|
use ncc\Enums\Flags\PackageFlags;
|
||||||
use ncc\Enums\PackageDirectory;
|
use ncc\Enums\PackageDirectory;
|
||||||
use ncc\Exceptions\ConfigurationException;
|
use ncc\Exceptions\ConfigurationException;
|
||||||
|
use ncc\Exceptions\IntegrityException;
|
||||||
use ncc\Exceptions\IOException;
|
use ncc\Exceptions\IOException;
|
||||||
use ncc\Exceptions\NotSupportedException;
|
|
||||||
use ncc\Objects\Package\Component;
|
use ncc\Objects\Package\Component;
|
||||||
use ncc\Objects\Package\ExecutionUnit;
|
use ncc\Objects\Package\ExecutionUnit;
|
||||||
use ncc\Objects\Package\Metadata;
|
use ncc\Objects\Package\Metadata;
|
||||||
|
@ -317,6 +317,7 @@
|
||||||
*
|
*
|
||||||
* @return Assembly
|
* @return Assembly
|
||||||
* @throws ConfigurationException
|
* @throws ConfigurationException
|
||||||
|
* @throws IntegrityException
|
||||||
*/
|
*/
|
||||||
public function getAssembly(): Assembly
|
public function getAssembly(): Assembly
|
||||||
{
|
{
|
||||||
|
@ -332,7 +333,15 @@
|
||||||
throw new ConfigurationException('Package does not contain an assembly');
|
throw new ConfigurationException('Package does not contain an assembly');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
$assembly = Assembly::fromArray(ZiProto::decode($this->get($directory)));
|
$assembly = Assembly::fromArray(ZiProto::decode($this->get($directory)));
|
||||||
|
}
|
||||||
|
catch(Exception $e)
|
||||||
|
{
|
||||||
|
throw new IntegrityException(sprintf('Failed to decode assembly from package using ZiProto: %s', $e->getMessage()), $e);
|
||||||
|
}
|
||||||
|
|
||||||
$this->cache[$directory] = $assembly;
|
$this->cache[$directory] = $assembly;
|
||||||
return $assembly;
|
return $assembly;
|
||||||
}
|
}
|
||||||
|
@ -342,7 +351,7 @@
|
||||||
*
|
*
|
||||||
* @return Metadata
|
* @return Metadata
|
||||||
* @throws ConfigurationException
|
* @throws ConfigurationException
|
||||||
* @throws NotSupportedException
|
* @throws IntegrityException
|
||||||
*/
|
*/
|
||||||
public function getMetadata(): Metadata
|
public function getMetadata(): Metadata
|
||||||
{
|
{
|
||||||
|
@ -358,7 +367,15 @@
|
||||||
throw new ConfigurationException('Package does not contain metadata');
|
throw new ConfigurationException('Package does not contain metadata');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
$metadata = Metadata::fromArray(ZiProto::decode($this->get($directory)));
|
$metadata = Metadata::fromArray(ZiProto::decode($this->get($directory)));
|
||||||
|
}
|
||||||
|
catch(Exception $e)
|
||||||
|
{
|
||||||
|
throw new IntegrityException(sprintf('Failed to decode metadata from package using ZiProto: %s', $e->getMessage()), $e);
|
||||||
|
}
|
||||||
|
|
||||||
foreach($this->getFlags() as $flag)
|
foreach($this->getFlags() as $flag)
|
||||||
{
|
{
|
||||||
$metadata->setOption($flag, true);
|
$metadata->setOption($flag, true);
|
||||||
|
@ -372,6 +389,7 @@
|
||||||
* Optional. Returns the package's installer
|
* Optional. Returns the package's installer
|
||||||
*
|
*
|
||||||
* @return Installer|null
|
* @return Installer|null
|
||||||
|
* @throws IntegrityException
|
||||||
*/
|
*/
|
||||||
public function getInstaller(): ?Installer
|
public function getInstaller(): ?Installer
|
||||||
{
|
{
|
||||||
|
@ -387,7 +405,15 @@
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
$installer = Installer::fromArray(ZiProto::decode($this->get($directory)));
|
$installer = Installer::fromArray(ZiProto::decode($this->get($directory)));
|
||||||
|
}
|
||||||
|
catch(Exception $e)
|
||||||
|
{
|
||||||
|
throw new IntegrityException(sprintf('Failed to decode installer from package using ZiProto: %s', $e->getMessage()), $e);
|
||||||
|
}
|
||||||
|
|
||||||
$this->cache[$directory] = $installer;
|
$this->cache[$directory] = $installer;
|
||||||
return $installer;
|
return $installer;
|
||||||
}
|
}
|
||||||
|
@ -419,6 +445,7 @@
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @return Dependency
|
* @return Dependency
|
||||||
* @throws ConfigurationException
|
* @throws ConfigurationException
|
||||||
|
* @throws IntegrityException
|
||||||
*/
|
*/
|
||||||
public function getDependency(string $name): Dependency
|
public function getDependency(string $name): Dependency
|
||||||
{
|
{
|
||||||
|
@ -428,8 +455,15 @@
|
||||||
throw new ConfigurationException(sprintf('Dependency \'%s\' not found in package', $name));
|
throw new ConfigurationException(sprintf('Dependency \'%s\' not found in package', $name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
return Dependency::fromArray(ZiProto::decode($this->get($dependency_name)));
|
return Dependency::fromArray(ZiProto::decode($this->get($dependency_name)));
|
||||||
}
|
}
|
||||||
|
catch(Exception $e)
|
||||||
|
{
|
||||||
|
throw new IntegrityException(sprintf('Failed to decode dependency \'%s\' from package using ZiProto: %s', $name, $e->getMessage()), $e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a dependency from the package by pointer
|
* Returns a dependency from the package by pointer
|
||||||
|
@ -437,12 +471,19 @@
|
||||||
* @param int $pointer
|
* @param int $pointer
|
||||||
* @param int $length
|
* @param int $length
|
||||||
* @return Dependency
|
* @return Dependency
|
||||||
* @throws ConfigurationException
|
* @throws IntegrityException
|
||||||
*/
|
*/
|
||||||
public function getDependencyByPointer(int $pointer, int $length): Dependency
|
public function getDependencyByPointer(int $pointer, int $length): Dependency
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
return Dependency::fromArray(ZiProto::decode($this->getByPointer($pointer, $length)));
|
return Dependency::fromArray(ZiProto::decode($this->getByPointer($pointer, $length)));
|
||||||
}
|
}
|
||||||
|
catch(Exception $e)
|
||||||
|
{
|
||||||
|
throw new IntegrityException(sprintf('Failed to decode dependency from pointer \'%s\' with length \'%s\' from package using ZiProto: %s', $pointer, $length, $e->getMessage()), $e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an array of execution units from the package
|
* Returns an array of execution units from the package
|
||||||
|
@ -471,6 +512,7 @@
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @return ExecutionUnit
|
* @return ExecutionUnit
|
||||||
* @throws ConfigurationException
|
* @throws ConfigurationException
|
||||||
|
* @throws IntegrityException
|
||||||
*/
|
*/
|
||||||
public function getExecutionUnit(string $name): ExecutionUnit
|
public function getExecutionUnit(string $name): ExecutionUnit
|
||||||
{
|
{
|
||||||
|
@ -480,8 +522,15 @@
|
||||||
throw new ConfigurationException(sprintf('Execution unit \'%s\' not found in package', $name));
|
throw new ConfigurationException(sprintf('Execution unit \'%s\' not found in package', $name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
return ExecutionUnit::fromArray(ZiProto::decode($this->get($execution_unit_name)));
|
return ExecutionUnit::fromArray(ZiProto::decode($this->get($execution_unit_name)));
|
||||||
}
|
}
|
||||||
|
catch(Exception $e)
|
||||||
|
{
|
||||||
|
throw new IntegrityException(sprintf('Failed to decode execution unit \'%s\' from package using ZiProto: %s', $name, $e->getMessage()), $e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an execution unit from the package by pointer
|
* Returns an execution unit from the package by pointer
|
||||||
|
@ -489,12 +538,19 @@
|
||||||
* @param int $pointer
|
* @param int $pointer
|
||||||
* @param int $length
|
* @param int $length
|
||||||
* @return ExecutionUnit
|
* @return ExecutionUnit
|
||||||
* @throws ConfigurationException
|
* @throws IntegrityException
|
||||||
*/
|
*/
|
||||||
public function getExecutionUnitByPointer(int $pointer, int $length): ExecutionUnit
|
public function getExecutionUnitByPointer(int $pointer, int $length): ExecutionUnit
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
return ExecutionUnit::fromArray(ZiProto::decode($this->getByPointer($pointer, $length)));
|
return ExecutionUnit::fromArray(ZiProto::decode($this->getByPointer($pointer, $length)));
|
||||||
}
|
}
|
||||||
|
catch(Exception $e)
|
||||||
|
{
|
||||||
|
throw new IntegrityException(sprintf('Failed to decode execution unit from pointer \'%s\' with length \'%s\' from package using ZiProto: %s', $pointer, $length, $e->getMessage()), $e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the package's component pointers
|
* Returns the package's component pointers
|
||||||
|
@ -544,6 +600,7 @@
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @return Component
|
* @return Component
|
||||||
* @throws ConfigurationException
|
* @throws ConfigurationException
|
||||||
|
* @throws IntegrityException
|
||||||
*/
|
*/
|
||||||
public function getComponent(string $name): Component
|
public function getComponent(string $name): Component
|
||||||
{
|
{
|
||||||
|
@ -553,8 +610,15 @@
|
||||||
throw new ConfigurationException(sprintf('Component \'%s\' not found in package', $name));
|
throw new ConfigurationException(sprintf('Component \'%s\' not found in package', $name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
return Component::fromArray(ZiProto::decode($this->get($component_name)));
|
return Component::fromArray(ZiProto::decode($this->get($component_name)));
|
||||||
}
|
}
|
||||||
|
catch(Exception $e)
|
||||||
|
{
|
||||||
|
throw new IntegrityException(sprintf('Failed to decode component \'%s\' from package using ZiProto: %s', $name, $e->getMessage()), $e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a component from the package by pointer
|
* Returns a component from the package by pointer
|
||||||
|
@ -562,12 +626,19 @@
|
||||||
* @param int $pointer
|
* @param int $pointer
|
||||||
* @param int $length
|
* @param int $length
|
||||||
* @return Component
|
* @return Component
|
||||||
* @throws ConfigurationException
|
* @throws IntegrityException
|
||||||
*/
|
*/
|
||||||
public function getComponentByPointer(int $pointer, int $length): Component
|
public function getComponentByPointer(int $pointer, int $length): Component
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
return Component::fromArray(ZiProto::decode($this->getByPointer($pointer, $length)));
|
return Component::fromArray(ZiProto::decode($this->getByPointer($pointer, $length)));
|
||||||
}
|
}
|
||||||
|
catch(Exception $e)
|
||||||
|
{
|
||||||
|
throw new IntegrityException(sprintf('Failed to decode component from pointer \'%s\' with length \'%s\' from package using ZiProto: %s', $pointer, $length, $e->getMessage()), $e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a component from the package by a class pointer
|
* Returns a component from the package by a class pointer
|
||||||
|
@ -575,6 +646,7 @@
|
||||||
* @param string $class
|
* @param string $class
|
||||||
* @return Component
|
* @return Component
|
||||||
* @throws ConfigurationException
|
* @throws ConfigurationException
|
||||||
|
* @throws IntegrityException
|
||||||
*/
|
*/
|
||||||
public function getComponentByClass(string $class): Component
|
public function getComponentByClass(string $class): Component
|
||||||
{
|
{
|
||||||
|
@ -584,8 +656,15 @@
|
||||||
throw new ConfigurationException(sprintf('Class map \'%s\' not found in package', $class));
|
throw new ConfigurationException(sprintf('Class map \'%s\' not found in package', $class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
return Component::fromArray(ZiProto::decode($this->get($class_name)));
|
return Component::fromArray(ZiProto::decode($this->get($class_name)));
|
||||||
}
|
}
|
||||||
|
catch(Exception $e)
|
||||||
|
{
|
||||||
|
throw new IntegrityException(sprintf('Failed to decode component from class pointer \'%s\' from package using ZiProto: %s', $class, $e->getMessage()), $e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an array of resource pointers from the package
|
* Returns an array of resource pointers from the package
|
||||||
|
@ -614,6 +693,7 @@
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @return Resource
|
* @return Resource
|
||||||
* @throws ConfigurationException
|
* @throws ConfigurationException
|
||||||
|
* @throws IntegrityException
|
||||||
*/
|
*/
|
||||||
public function getResource(string $name): Resource
|
public function getResource(string $name): Resource
|
||||||
{
|
{
|
||||||
|
@ -623,8 +703,15 @@
|
||||||
throw new ConfigurationException(sprintf('Resource \'%s\' not found in package', $name));
|
throw new ConfigurationException(sprintf('Resource \'%s\' not found in package', $name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
return Resource::fromArray(ZiProto::decode($this->get($resource_name)));
|
return Resource::fromArray(ZiProto::decode($this->get($resource_name)));
|
||||||
}
|
}
|
||||||
|
catch(Exception $e)
|
||||||
|
{
|
||||||
|
throw new IntegrityException(sprintf('Failed to decode resource \'%s\' from package using ZiProto: %s', $name, $e->getMessage()), $e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a resource from the package by pointer
|
* Returns a resource from the package by pointer
|
||||||
|
@ -632,12 +719,19 @@
|
||||||
* @param int $pointer
|
* @param int $pointer
|
||||||
* @param int $length
|
* @param int $length
|
||||||
* @return Resource
|
* @return Resource
|
||||||
* @throws ConfigurationException
|
* @throws IntegrityException
|
||||||
*/
|
*/
|
||||||
public function getResourceByPointer(int $pointer, int $length): Resource
|
public function getResourceByPointer(int $pointer, int $length): Resource
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
return Resource::fromArray(ZiProto::decode($this->getByPointer($pointer, $length)));
|
return Resource::fromArray(ZiProto::decode($this->getByPointer($pointer, $length)));
|
||||||
}
|
}
|
||||||
|
catch(Exception $e)
|
||||||
|
{
|
||||||
|
throw new IntegrityException(sprintf('Failed to decode resource from pointer \'%s\' with length \'%s\' from package using ZiProto: %s', $pointer, $length, $e->getMessage()), $e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Searches the package's directory for a file that matches the given filename
|
* Searches the package's directory for a file that matches the given filename
|
||||||
|
@ -755,7 +849,7 @@
|
||||||
fseek($this->package_file, $this->package_offset);
|
fseek($this->package_file, $this->package_offset);
|
||||||
$remaining_bytes = $this->package_length;
|
$remaining_bytes = $this->package_length;
|
||||||
|
|
||||||
while ($remaining_bytes > 0)
|
while($remaining_bytes > 0)
|
||||||
{
|
{
|
||||||
$bytes_to_read = min($remaining_bytes, 4096);
|
$bytes_to_read = min($remaining_bytes, 4096);
|
||||||
$data = fread($this->package_file, $bytes_to_read);
|
$data = fread($this->package_file, $bytes_to_read);
|
||||||
|
|
Loading…
Add table
Reference in a new issue