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/tests/downloader/download_manager_test.rs | 8 +------- crates/shirabe/tests/downloader/file_downloader_test.rs | 9 +++++---- 2 files changed, 6 insertions(+), 11 deletions(-) (limited to 'crates/shirabe/tests/downloader') diff --git a/crates/shirabe/tests/downloader/download_manager_test.rs b/crates/shirabe/tests/downloader/download_manager_test.rs index 9d12bad6..dd894565 100644 --- a/crates/shirabe/tests/downloader/download_manager_test.rs +++ b/crates/shirabe/tests/downloader/download_manager_test.rs @@ -253,13 +253,7 @@ fn test_full_package_download_failover() { .expect_download() .times(1) .withf(|_pkg, path, _prev, _output| path == "target_dir") - .returning(|_, _, _, _| { - Err(RuntimeException { - message: "Foo".to_string(), - code: 0, - } - .into()) - }); + .returning(|_, _, _, _| Err(RuntimeException::new("Foo".to_string()).into())); let mut downloader_success = downloader_mock("source"); downloader_success diff --git a/crates/shirabe/tests/downloader/file_downloader_test.rs b/crates/shirabe/tests/downloader/file_downloader_test.rs index 469bf473..eac4e45e 100644 --- a/crates/shirabe/tests/downloader/file_downloader_test.rs +++ b/crates/shirabe/tests/downloader/file_downloader_test.rs @@ -17,6 +17,7 @@ use shirabe::util::HttpDownloader; use shirabe::util::filesystem::{Filesystem, FilesystemMock}; use shirabe::util::http_downloader::HttpDownloaderMockHandler; use shirabe::util::r#loop::Loop; +use shirabe_php_shim::Catch as _; use shirabe_php_shim::{ InvalidArgumentException, PhpMixed, RuntimeException, UnexpectedValueException, }; @@ -84,7 +85,7 @@ fn test_download_for_package_without_dist_reference() { let e = result.expect_err("expected InvalidArgumentException"); assert!( - e.downcast_ref::().is_some(), + e.is_instanceof::(), "expected InvalidArgumentException, got: {e}" ); } @@ -107,7 +108,7 @@ fn test_download_to_existing_file() { let e = result.expect_err("download to an existing file was expected to throw"); assert!( - e.downcast_ref::().is_some(), + e.is_instanceof::(), "expected RuntimeException, got: {e}" ); assert!( @@ -167,7 +168,7 @@ fn test_download_but_file_is_unsaved() { let e = result.expect_err("download was expected to throw"); assert!( - e.downcast_ref::().is_some(), + e.is_instanceof::(), "expected UnexpectedValueException, got: {e}" ); assert!( @@ -294,7 +295,7 @@ fn test_download_file_with_invalid_checksum() { let e = result.expect_err("download was expected to throw"); assert!( - e.downcast_ref::().is_some(), + e.is_instanceof::(), "expected UnexpectedValueException, got: {e}" ); assert!( -- cgit v1.3.1-4-g156e