diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-08-08 22:14:12 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-08-08 22:14:12 +0900 |
| commit | f4cad2123b2af0de72bda4ce039e16e74f163f4e (patch) | |
| tree | 21803308c5ff41e23c9d3b117433eea16b4ff663 /crates/shirabe/tests/repository/vcs | |
| parent | 0209f63210e5b547b5c6b73367bb80ea86c255ec (diff) | |
| download | php-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/tests/repository/vcs')
4 files changed, 13 insertions, 9 deletions
diff --git a/crates/shirabe/tests/repository/vcs/git_bitbucket_driver_test.rs b/crates/shirabe/tests/repository/vcs/git_bitbucket_driver_test.rs index 4d84bcf2..67e9c8a9 100644 --- a/crates/shirabe/tests/repository/vcs/git_bitbucket_driver_test.rs +++ b/crates/shirabe/tests/repository/vcs/git_bitbucket_driver_test.rs @@ -10,6 +10,7 @@ use shirabe::repository::vcs::GitBitbucketDriver; use shirabe::util::filesystem::Filesystem; use shirabe::util::http_downloader::{HttpDownloader, HttpDownloaderMockHandler}; use shirabe::util::process_executor::ProcessExecutor; +use shirabe_php_shim::Catch as _; use shirabe_php_shim::{InvalidArgumentException, PhpMixed, RuntimeException}; use tempfile::TempDir; @@ -112,11 +113,11 @@ fn test_get_root_identifier_wrong_scm_type() { let err = driver.get_root_identifier().unwrap_err(); let runtime = err - .downcast_ref::<RuntimeException>() + .catch::<RuntimeException>() .expect("expected RuntimeException"); assert_eq!( "https://bitbucket.org/user/repo.git does not appear to be a git repository, use https://bitbucket.org/user/repo but remember that Bitbucket no longer supports the mercurial repositories. https://bitbucket.org/blog/sunsetting-mercurial-support-in-bitbucket", - runtime.message + runtime.get_message() ); } @@ -250,7 +251,7 @@ fn test_initialize_invalid_repository_url() { let result = get_driver("https://bitbucket.org/acme", io, config, http_downloader); let err = result.unwrap_err(); assert!( - err.downcast_ref::<InvalidArgumentException>().is_some(), + err.is_instanceof::<InvalidArgumentException>(), "expected InvalidArgumentException, got: {err:?}" ); } diff --git a/crates/shirabe/tests/repository/vcs/git_driver_test.rs b/crates/shirabe/tests/repository/vcs/git_driver_test.rs index 7a85d4cc..8494c1ca 100644 --- a/crates/shirabe/tests/repository/vcs/git_driver_test.rs +++ b/crates/shirabe/tests/repository/vcs/git_driver_test.rs @@ -12,6 +12,7 @@ use shirabe::util::filesystem::Filesystem; use shirabe::util::http_downloader::HttpDownloaderMockHandler; use shirabe::util::platform::Platform; use shirabe::util::process_executor::MockHandler; +use shirabe_php_shim::Catch as _; use shirabe_php_shim::{PhpMixed, RuntimeException}; use tempfile::TempDir; @@ -293,7 +294,7 @@ fn test_file_get_content_invalid_identifier() { assert_eq!(None, driver.get_file_content("file.txt", "h").unwrap()); let err = driver.get_file_content("file.txt", "-h").unwrap_err(); - assert!(err.downcast_ref::<RuntimeException>().is_some()); + assert!(err.is_instanceof::<RuntimeException>()); } #[test] @@ -324,5 +325,5 @@ fn test_get_change_date_invalid_identifier() { let mut driver = GitDriver::new(repo_config, io, config, http_downloader, process); let err = driver.get_change_date("-n1 --format=%at HEAD").unwrap_err(); - assert!(err.downcast_ref::<RuntimeException>().is_some()); + assert!(err.is_instanceof::<RuntimeException>()); } diff --git a/crates/shirabe/tests/repository/vcs/hg_driver_test.rs b/crates/shirabe/tests/repository/vcs/hg_driver_test.rs index be36f412..4245e140 100644 --- a/crates/shirabe/tests/repository/vcs/hg_driver_test.rs +++ b/crates/shirabe/tests/repository/vcs/hg_driver_test.rs @@ -11,6 +11,7 @@ use shirabe::repository::vcs::HgDriver; use shirabe::util::filesystem::Filesystem; use shirabe::util::http_downloader::HttpDownloaderMockHandler; use shirabe::util::process_executor::MockHandler; +use shirabe_php_shim::Catch as _; use shirabe_php_shim::{PhpMixed, RuntimeException}; use tempfile::TempDir; @@ -141,7 +142,7 @@ fn test_file_get_content_invalid_identifier() { assert_eq!(None, driver.get_file_content("file.txt", "h").unwrap()); let err = driver.get_file_content("file.txt", "-h").unwrap_err(); - assert!(err.downcast_ref::<RuntimeException>().is_some()); + assert!(err.is_instanceof::<RuntimeException>()); } #[test] @@ -168,5 +169,5 @@ fn test_get_change_date_invalid_identifier() { let driver = HgDriver::new(repo_config, io, config, http_downloader, process); let err = driver.get_change_date("-r foo").unwrap_err(); - assert!(err.downcast_ref::<RuntimeException>().is_some()); + assert!(err.is_instanceof::<RuntimeException>()); } diff --git a/crates/shirabe/tests/repository/vcs/svn_driver_test.rs b/crates/shirabe/tests/repository/vcs/svn_driver_test.rs index 6a74063d..bc45b082 100644 --- a/crates/shirabe/tests/repository/vcs/svn_driver_test.rs +++ b/crates/shirabe/tests/repository/vcs/svn_driver_test.rs @@ -11,6 +11,7 @@ use shirabe::repository::vcs::SvnDriver; use shirabe::util::filesystem::Filesystem; use shirabe::util::http_downloader::HttpDownloaderMockHandler; use shirabe::util::process_executor::MockHandler; +use shirabe_php_shim::Catch as _; use shirabe_php_shim::{PhpMixed, RuntimeException}; use tempfile::TempDir; @@ -130,10 +131,10 @@ fn test_wrong_credentials_in_url() { let mut svn = SvnDriver::new(repo_config, console, config, http_downloader, process); let err = svn.initialize().unwrap_err(); let runtime = err - .downcast_ref::<RuntimeException>() + .catch::<RuntimeException>() .expect("expected RuntimeException"); assert_eq!( "Repository https://till:secret@corp.svn.local/repo could not be processed, wrong credentials provided (svn: OPTIONS of 'https://corp.svn.local/repo': authorization failed: Could not authenticate to server: rejected Basic challenge (https://corp.svn.local/))", - runtime.message + runtime.get_message() ); } |
