aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/repository/package_repository.rs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-08 22:14:12 +0900
committernsfisis <nsfisis@gmail.com>2026-08-08 22:14:12 +0900
commitf4cad2123b2af0de72bda4ce039e16e74f163f4e (patch)
tree21803308c5ff41e23c9d3b117433eea16b4ff663 /crates/shirabe/src/repository/package_repository.rs
parent0209f63210e5b547b5c6b73367bb80ea86c255ec (diff)
downloadphp-shirabe-f4cad2123b2af0de72bda4ce039e16e74f163f4e.tar.gz
php-shirabe-f4cad2123b2af0de72bda4ce039e16e74f163f4e.tar.zst
php-shirabe-f4cad2123b2af0de72bda4ce039e16e74f163f4e.zip
feat(php-shim): give ported exceptions PHP's class hierarchy
Ported exceptions were flat structs reached with `downcast_ref`, so Composer's `catch (\RuntimeException $e)` only matched the exact leaf type and `get_class($e)` had nothing to report. Each exception now embeds an instance of the class it extends and travels inside an `AnyThrowable`; `Catch::catch`/`catch_mut` walk that chain, and `PhpClass::php_class_name` yields the PHP FQCN. Dropping the `std::error::Error` impls from the exception types leaves `AnyThrowable` as the only route into an `anyhow::Error`, so the walk cannot be bypassed. A `no_exception_downcast` linter catches the `downcast::<X>()` calls that would now silently answer `None`. Three sites change behavior as a result: the `TransportException` exit-code override reaches `MaxFileSizeExceededException`, the `catch (\LogicException)` in findSimilar() reaches its subclasses, and rendered exception titles carry the real class name rather than a guess. `get_class_err()` is no longer a `todo!()`, which re-enables FilesystemRepositoryTest::testCorruptedRepositoryFile. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/repository/package_repository.rs')
-rw-r--r--crates/shirabe/src/repository/package_repository.rs25
1 files changed, 10 insertions, 15 deletions
diff --git a/crates/shirabe/src/repository/package_repository.rs b/crates/shirabe/src/repository/package_repository.rs
index 62c8c5b3..810b0e13 100644
--- a/crates/shirabe/src/repository/package_repository.rs
+++ b/crates/shirabe/src/repository/package_repository.rs
@@ -16,7 +16,7 @@ use crate::repository::{
};
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::Preg;
-use shirabe_php_shim::{Exception, PhpMixed, RuntimeException, php_regex, var_export};
+use shirabe_php_shim::{PhpMixed, RuntimeException, php_regex, var_export};
use shirabe_semver::constraint::AnyConstraint;
#[derive(Debug)]
@@ -72,10 +72,7 @@ impl PackageRepository {
e,
shirabe_php_shim::json_encode(package).unwrap_or_default()
);
- return Ok(Err(InvalidRepositoryException(Exception {
- message: msg,
- code: 0,
- })));
+ return Ok(Err(InvalidRepositoryException::new(msg)));
}
};
self.inner.add_package(package_loaded)?;
@@ -101,7 +98,7 @@ impl PackageRepository {
// skips re-initializing it.
fn ensure_initialized(&self) -> anyhow::Result<()> {
if !self.inner.is_initialized() {
- self.initialize()?.map_err(anyhow::Error::new)?;
+ self.initialize()?.map_err(anyhow::Error::from)?;
}
Ok(())
}
@@ -234,15 +231,13 @@ impl AdvisoryProviderInterface for PackageRepository {
};
if !allow_partial_advisories && matches!(advisory, AnySecurityAdvisory::Partial(_))
{
- return Err(anyhow::anyhow!(RuntimeException {
- message: format!(
- "Advisory for {} could not be loaded as a full advisory from {}\n{}",
- package_name,
- self.get_repo_name()?,
- var_export(data, true)
- ),
- code: 0,
- }));
+ return Err(RuntimeException::new(format!(
+ "Advisory for {} could not be loaded as a full advisory from {}\n{}",
+ package_name,
+ self.get_repo_name()?,
+ var_export(data, true)
+ ))
+ .into());
}
if !advisory.affected_versions().matches(package_constraint) {