From f4cad2123b2af0de72bda4ce039e16e74f163f4e Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 8 Aug 2026 22:14:12 +0900 Subject: 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::()` 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) --- crates/shirabe/src/command/run_script_command.rs | 38 +++++++++++------------- 1 file changed, 18 insertions(+), 20 deletions(-) (limited to 'crates/shirabe/src/command/run_script_command.rs') diff --git a/crates/shirabe/src/command/run_script_command.rs b/crates/shirabe/src/command/run_script_command.rs index fe020de3..be50c4be 100644 --- a/crates/shirabe/src/command/run_script_command.rs +++ b/crates/shirabe/src/command/run_script_command.rs @@ -16,6 +16,7 @@ use shirabe_external_packages::symfony::console::exception::CommandNotFoundExcep use shirabe_external_packages::symfony::console::exception::namespace_not_found_exception::NamespaceNotFoundException; use shirabe_external_packages::symfony::console::input::InputInterface; use shirabe_external_packages::symfony::console::output::OutputInterface; +use shirabe_php_shim::Catch as _; use shirabe_php_shim::{InvalidArgumentException, RuntimeException}; use shirabe_php_shim::{PhpMixed, impl_php_class}; @@ -102,8 +103,8 @@ impl RunScriptCommand { match application.borrow_mut().find(&name) { Ok(cmd) => description = cmd.borrow().get_description(), Err(e) - if e.downcast_ref::().is_some() - || e.downcast_ref::().is_some() => {} + if e.is_instanceof::() + || e.is_instanceof::() => {} Err(e) => return Err(e), } } @@ -255,10 +256,9 @@ impl Command for RunScriptCommand { let script = match input.borrow().get_argument("script")?.as_string() { None => { - return Err(RuntimeException { - message: "Missing required argument \"script\"".to_string(), - code: 0, - } + return Err(RuntimeException::new( + "Missing required argument \"script\"".to_string(), + ) .into()); } Some(s) => s.to_string(), @@ -267,10 +267,10 @@ impl Command for RunScriptCommand { if !self.script_events.contains(&script.as_str()) { let const_name = script.to_uppercase().replace('-', "_"); if ScriptEvents::is_defined(&const_name) { - return Err(InvalidArgumentException { - message: format!("Script \"{}\" cannot be run with this command", script), - code: 0, - } + return Err(InvalidArgumentException::new(format!( + "Script \"{}\" cannot be run with this command", + script + )) .into()); } } @@ -299,10 +299,10 @@ impl Command for RunScriptCommand { ); let has_listeners = dispatcher.borrow_mut().has_event_listeners(&event); if !has_listeners { - return Err(InvalidArgumentException { - message: format!("Script \"{}\" is not defined in this package", script), - code: 0, - } + return Err(InvalidArgumentException::new(format!( + "Script \"{}\" is not defined in this package", + script + )) .into()); } @@ -320,12 +320,10 @@ impl Command for RunScriptCommand { if let Some(timeout_val) = input.borrow().get_option("timeout")?.as_string() { let timeout_str = timeout_val.to_string(); if !timeout_str.chars().all(|c| c.is_ascii_digit()) { - return Err(RuntimeException { - message: - "Timeout value must be numeric and positive if defined, or 0 for forever" - .to_string(), - code: 0, - } + return Err(RuntimeException::new( + "Timeout value must be numeric and positive if defined, or 0 for forever" + .to_string(), + ) .into()); } let timeout: i64 = timeout_str.parse().unwrap_or(0); -- cgit v1.3.1-4-g156e