aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/plugin/plugin_manager.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/plugin/plugin_manager.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/plugin/plugin_manager.rs')
-rw-r--r--crates/shirabe/src/plugin/plugin_manager.rs84
1 files changed, 30 insertions, 54 deletions
diff --git a/crates/shirabe/src/plugin/plugin_manager.rs b/crates/shirabe/src/plugin/plugin_manager.rs
index 18239ce9..c68708a5 100644
--- a/crates/shirabe/src/plugin/plugin_manager.rs
+++ b/crates/shirabe/src/plugin/plugin_manager.rs
@@ -234,10 +234,7 @@ impl PluginManager {
let requires_composer = match requires_composer {
Some(r) => r,
None => {
- return Err(RuntimeException {
- message: format!("Plugin {} is missing a require statement for a version of the composer-plugin-api package.", package.get_name()),
- code: 0,
- }.into());
+ return Err(RuntimeException::new(format!("Plugin {} is missing a require statement for a version of the composer-plugin-api package.", package.get_name())).into());
}
};
@@ -316,10 +313,7 @@ impl PluginManager {
_ => false,
};
if class_is_empty {
- return Err(UnexpectedValueException {
- message: format!("Error while installing {}, composer-plugin packages should have a class defined in their extra key to be usable.", package.get_pretty_name()),
- code: 0,
- }.into());
+ return Err(UnexpectedValueException::new(format!("Error while installing {}, composer-plugin packages should have a class defined in their extra key to be usable.", package.get_pretty_name())).into());
}
// PHP: is_array($extra['class']) ? $extra['class'] : [$extra['class']] — an associative
// array iterates its values too, and a non-string entry reaches class_exists() where it
@@ -470,14 +464,11 @@ impl PluginManager {
if old_installer_plugin {
if !self.php_runtime_is_a(&class, "Composer\\Installer\\InstallerInterface")? {
- return Err(RuntimeException {
- message: format!(
- "Could not activate plugin \"{}\" as \"{}\" does not implement Composer\\Installer\\InstallerInterface",
- package.get_name(),
- class
- ),
- code: 0,
- }
+ return Err(RuntimeException::new(format!(
+ "Could not activate plugin \"{}\" as \"{}\" does not implement Composer\\Installer\\InstallerInterface",
+ package.get_name(),
+ class
+ ))
.into());
}
self.io.write_error(&format!(
@@ -511,14 +502,11 @@ impl PluginManager {
.push(PluginOrInstaller::Installer(installer));
} else if self.php_runtime_class_exists(&class, true)? {
if !self.php_runtime_is_a(&class, "Composer\\Plugin\\PluginInterface")? {
- return Err(RuntimeException {
- message: format!(
- "Could not activate plugin \"{}\" as \"{}\" does not implement Composer\\Plugin\\PluginInterface",
- package.get_name(),
- class
- ),
- code: 0,
- }
+ return Err(RuntimeException::new(format!(
+ "Could not activate plugin \"{}\" as \"{}\" does not implement Composer\\Plugin\\PluginInterface",
+ package.get_name(),
+ class
+ ))
.into());
}
let handle = self.php_runtime_new_object(&class)?;
@@ -534,14 +522,11 @@ impl PluginManager {
.or_default()
.push(PluginOrInstaller::Plugin(plugin));
} else if fail_on_missing_classes {
- return Err(UnexpectedValueException {
- message: format!(
- "Plugin {} could not be initialized, class not found: {}",
- package.get_name(),
- class
- ),
- code: 0,
- }
+ return Err(UnexpectedValueException::new(format!(
+ "Plugin {} could not be initialized, class not found: {}",
+ package.get_name(),
+ class
+ ))
.into());
}
}
@@ -1033,14 +1018,11 @@ impl PluginManager {
// || !trim(...)). Once the first branch has declined, a present key always fails one
// of the three disjuncts, so a present key unconditionally throws here.
if let Some(value) = capabilities.get(capability) {
- return Err(UnexpectedValueException {
- message: format!(
- "Plugin {} provided invalid capability class name(s), got {}",
- plugin.get_class_name(),
- var_export(value, true)
- ),
- code: 0,
- }
+ return Err(UnexpectedValueException::new(format!(
+ "Plugin {} provided invalid capability class name(s), got {}",
+ plugin.get_class_name(),
+ var_export(value, true)
+ ))
.into());
}
@@ -1066,14 +1048,11 @@ impl PluginManager {
Some(&mut PluginRpcDispatcher::default()),
))?;
if !matches!(exists, PluginValue::Bool(true)) {
- return Err(RuntimeException {
- message: format!(
- "Cannot instantiate Capability, as class {} from plugin {} does not exist.",
- capability_class,
- plugin.get_class_name()
- ),
- code: 0,
- }
+ return Err(RuntimeException::new(format!(
+ "Cannot instantiate Capability, as class {} from plugin {} does not exist.",
+ capability_class,
+ plugin.get_class_name()
+ ))
.into());
}
@@ -1116,12 +1095,9 @@ impl PluginManager {
if !php_is_a(&handle, "Composer\\Plugin\\Capability\\Capability")?
|| !php_is_a(&handle, capability_class_name)?
{
- return Err(RuntimeException {
- message: format!(
- "Class {capability_class} must implement both Composer\\Plugin\\Capability\\Capability and {capability_class_name}."
- ),
- code: 0,
- }
+ return Err(RuntimeException::new(format!(
+ "Class {capability_class} must implement both Composer\\Plugin\\Capability\\Capability and {capability_class_name}."
+ ))
.into());
}