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) --- .../exception/invalid_argument_exception.rs | 19 +++++++++---------- .../symfony/process/exception/logic_exception.rs | 19 +++++++++---------- .../process/exception/process_failed_exception.rs | 19 ++++++++----------- .../exception/process_signaled_exception.rs | 22 +++++++++++----------- .../exception/process_timed_out_exception.rs | 20 ++++++++++---------- .../symfony/process/exception/runtime_exception.rs | 19 +++++++++---------- 6 files changed, 56 insertions(+), 62 deletions(-) (limited to 'crates/shirabe-external-packages/src/symfony/process/exception') diff --git a/crates/shirabe-external-packages/src/symfony/process/exception/invalid_argument_exception.rs b/crates/shirabe-external-packages/src/symfony/process/exception/invalid_argument_exception.rs index b70a1d39..c9a42653 100644 --- a/crates/shirabe-external-packages/src/symfony/process/exception/invalid_argument_exception.rs +++ b/crates/shirabe-external-packages/src/symfony/process/exception/invalid_argument_exception.rs @@ -2,20 +2,19 @@ #[derive(Debug)] pub struct InvalidArgumentException { - pub message: String, - pub code: i64, + inner: shirabe_php_shim::InvalidArgumentException, } impl InvalidArgumentException { pub fn new(message: String) -> Self { - Self { message, code: 0 } + Self { + inner: shirabe_php_shim::InvalidArgumentException::new(message), + } } } -impl std::fmt::Display for InvalidArgumentException { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{}", self.message) - } -} - -impl std::error::Error for InvalidArgumentException {} +shirabe_php_shim::impl_php_exception!( + InvalidArgumentException, + inner, + r"Symfony\Component\Process\Exception\InvalidArgumentException" +); diff --git a/crates/shirabe-external-packages/src/symfony/process/exception/logic_exception.rs b/crates/shirabe-external-packages/src/symfony/process/exception/logic_exception.rs index c9a34661..36e9bcca 100644 --- a/crates/shirabe-external-packages/src/symfony/process/exception/logic_exception.rs +++ b/crates/shirabe-external-packages/src/symfony/process/exception/logic_exception.rs @@ -2,20 +2,19 @@ #[derive(Debug)] pub struct LogicException { - pub message: String, - pub code: i64, + inner: shirabe_php_shim::LogicException, } impl LogicException { pub fn new(message: String) -> Self { - Self { message, code: 0 } + Self { + inner: shirabe_php_shim::LogicException::new(message), + } } } -impl std::fmt::Display for LogicException { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{}", self.message) - } -} - -impl std::error::Error for LogicException {} +shirabe_php_shim::impl_php_exception!( + LogicException, + inner, + r"Symfony\Component\Process\Exception\LogicException" +); diff --git a/crates/shirabe-external-packages/src/symfony/process/exception/process_failed_exception.rs b/crates/shirabe-external-packages/src/symfony/process/exception/process_failed_exception.rs index b99e876a..e5d6d7fc 100644 --- a/crates/shirabe-external-packages/src/symfony/process/exception/process_failed_exception.rs +++ b/crates/shirabe-external-packages/src/symfony/process/exception/process_failed_exception.rs @@ -1,12 +1,12 @@ //! ref: composer/vendor/symfony/process/Exception/ProcessFailedException.php use crate::symfony::process::exception::invalid_argument_exception::InvalidArgumentException; +use crate::symfony::process::exception::runtime_exception::RuntimeException; use crate::symfony::process::process::Process; #[derive(Debug)] pub struct ProcessFailedException { - pub message: String, - pub code: i64, + inner: RuntimeException, } impl ProcessFailedException { @@ -36,16 +36,13 @@ impl ProcessFailedException { ); Ok(Self { - message: error, - code: 0, + inner: RuntimeException::new(error), }) } } -impl std::fmt::Display for ProcessFailedException { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{}", self.message) - } -} - -impl std::error::Error for ProcessFailedException {} +shirabe_php_shim::impl_php_exception!( + ProcessFailedException, + inner, + r"Symfony\Component\Process\Exception\ProcessFailedException" +); diff --git a/crates/shirabe-external-packages/src/symfony/process/exception/process_signaled_exception.rs b/crates/shirabe-external-packages/src/symfony/process/exception/process_signaled_exception.rs index 03c4df27..9f325750 100644 --- a/crates/shirabe-external-packages/src/symfony/process/exception/process_signaled_exception.rs +++ b/crates/shirabe-external-packages/src/symfony/process/exception/process_signaled_exception.rs @@ -1,11 +1,11 @@ //! ref: composer/vendor/symfony/process/Exception/ProcessSignaledException.php +use crate::symfony::process::exception::runtime_exception::RuntimeException; use crate::symfony::process::process::Process; #[derive(Debug)] pub struct ProcessSignaledException { - pub message: String, - pub code: i64, + inner: RuntimeException, signal: i64, } @@ -14,8 +14,10 @@ impl ProcessSignaledException { let signal = process.get_term_signal()?; Ok(Self { - message: format!("The process has been signaled with signal \"{}\".", signal), - code: 0, + inner: RuntimeException::new(format!( + "The process has been signaled with signal \"{}\".", + signal + )), signal, }) } @@ -25,10 +27,8 @@ impl ProcessSignaledException { } } -impl std::fmt::Display for ProcessSignaledException { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{}", self.message) - } -} - -impl std::error::Error for ProcessSignaledException {} +shirabe_php_shim::impl_php_exception!( + ProcessSignaledException, + inner, + r"Symfony\Component\Process\Exception\ProcessSignaledException" +); diff --git a/crates/shirabe-external-packages/src/symfony/process/exception/process_timed_out_exception.rs b/crates/shirabe-external-packages/src/symfony/process/exception/process_timed_out_exception.rs index 46564c37..9485d1c2 100644 --- a/crates/shirabe-external-packages/src/symfony/process/exception/process_timed_out_exception.rs +++ b/crates/shirabe-external-packages/src/symfony/process/exception/process_timed_out_exception.rs @@ -1,11 +1,11 @@ //! ref: composer/vendor/symfony/process/Exception/ProcessTimedOutException.php +use crate::symfony::process::exception::runtime_exception::RuntimeException; use crate::symfony::process::process::Process; #[derive(Debug)] pub struct ProcessTimedOutException { - pub message: String, - pub code: i64, + inner: RuntimeException, } impl ProcessTimedOutException { @@ -18,14 +18,14 @@ impl ProcessTimedOutException { exceeded_timeout.map(|t| t.to_string()).unwrap_or_default(), ); - Self { message, code: 0 } + Self { + inner: RuntimeException::new(message), + } } } -impl std::fmt::Display for ProcessTimedOutException { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{}", self.message) - } -} - -impl std::error::Error for ProcessTimedOutException {} +shirabe_php_shim::impl_php_exception!( + ProcessTimedOutException, + inner, + r"Symfony\Component\Process\Exception\ProcessTimedOutException" +); diff --git a/crates/shirabe-external-packages/src/symfony/process/exception/runtime_exception.rs b/crates/shirabe-external-packages/src/symfony/process/exception/runtime_exception.rs index 42422aff..e9cc31e0 100644 --- a/crates/shirabe-external-packages/src/symfony/process/exception/runtime_exception.rs +++ b/crates/shirabe-external-packages/src/symfony/process/exception/runtime_exception.rs @@ -2,20 +2,19 @@ #[derive(Debug)] pub struct RuntimeException { - pub message: String, - pub code: i64, + inner: shirabe_php_shim::RuntimeException, } impl RuntimeException { pub fn new(message: String) -> Self { - Self { message, code: 0 } + Self { + inner: shirabe_php_shim::RuntimeException::new(message), + } } } -impl std::fmt::Display for RuntimeException { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{}", self.message) - } -} - -impl std::error::Error for RuntimeException {} +shirabe_php_shim::impl_php_exception!( + RuntimeException, + inner, + r"Symfony\Component\Process\Exception\RuntimeException" +); -- cgit v1.3.1-4-g156e