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/repository/vcs/svn_driver.rs | 39 +++++++++++-------------- 1 file changed, 17 insertions(+), 22 deletions(-) (limited to 'crates/shirabe/src/repository/vcs/svn_driver.rs') diff --git a/crates/shirabe/src/repository/vcs/svn_driver.rs b/crates/shirabe/src/repository/vcs/svn_driver.rs index 716b1943..84e3a20d 100644 --- a/crates/shirabe/src/repository/vcs/svn_driver.rs +++ b/crates/shirabe/src/repository/vcs/svn_driver.rs @@ -14,6 +14,7 @@ use crate::util::Url; use chrono::{DateTime, FixedOffset, Utc}; use indexmap::IndexMap; use shirabe_external_packages::composer::pcre::{CaptureKey, Preg}; +use shirabe_php_shim::Catch as _; use shirabe_php_shim::{ PhpMixed, RuntimeException, php_regex, stripos, strrpos, strtr, substr, trim, }; @@ -199,14 +200,14 @@ impl SvnDriver { Ok(c) => c, Err(e) => { // PHP catches only TransportException; other exceptions propagate uncaught. - if e.downcast_ref::().is_none() { + if !e.is_instanceof::() { return Err(e); } let message = e - .downcast_ref::() + .catch::() .unwrap() - .message - .clone(); + .get_message() + .to_string(); if stripos(&message, "path not found").is_none() && stripos(&message, "svn: warning: W160013").is_none() { @@ -277,8 +278,8 @@ impl SvnDriver { ) { Ok(o) => o, Err(e) => { - if let Some(e) = e.downcast_ref::() { - return Err(TransportException::new(e.message.clone(), 0).into()); + if let Some(e) = e.catch::() { + return Err(TransportException::new(e.get_message().to_string(), 0).into()); } return Err(e); } @@ -567,24 +568,18 @@ impl SvnDriver { Ok(o) => Ok(o), Err(e) => { if self.util.as_mut().unwrap().binary_version().is_none() { - return Err(RuntimeException { - message: format!( - "Failed to load {}, svn was not found, check that it is installed and in your PATH env.\n\n{}", - self.inner.url, - self.inner.process.borrow().get_error_output(), - ), - code: 0, - } + return Err(RuntimeException::new(format!( + "Failed to load {}, svn was not found, check that it is installed and in your PATH env.\n\n{}", + self.inner.url, + self.inner.process.borrow().get_error_output(), + )) .into()); } - Err(RuntimeException { - message: format!( - "Repository {} could not be processed, {}", - self.inner.url, e, - ), - code: 0, - } + Err(RuntimeException::new(format!( + "Repository {} could not be processed, {}", + self.inner.url, e, + )) .into()) } } @@ -655,7 +650,7 @@ impl crate::repository::vcs::VcsDriverInterface for SvnDriver { match self.get_composer_information(identifier) { Ok(info) => Ok(info.is_some()), Err(e) => { - if e.downcast_ref::().is_some() { + if e.is_instanceof::() { Ok(false) } else { Err(e) -- cgit v1.3.1-4-g156e