aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/tests/downloader
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-08 22:14:12 +0900
committernsfisis <nsfisis@gmail.com>2026-08-08 22:14:12 +0900
commitf4cad2123b2af0de72bda4ce039e16e74f163f4e (patch)
tree21803308c5ff41e23c9d3b117433eea16b4ff663 /crates/shirabe/tests/downloader
parent0209f63210e5b547b5c6b73367bb80ea86c255ec (diff)
downloadphp-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/downloader')
-rw-r--r--crates/shirabe/tests/downloader/download_manager_test.rs8
-rw-r--r--crates/shirabe/tests/downloader/file_downloader_test.rs9
2 files changed, 6 insertions, 11 deletions
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::<InvalidArgumentException>().is_some(),
+ e.is_instanceof::<InvalidArgumentException>(),
"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::<RuntimeException>().is_some(),
+ e.is_instanceof::<RuntimeException>(),
"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::<UnexpectedValueException>().is_some(),
+ e.is_instanceof::<UnexpectedValueException>(),
"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::<UnexpectedValueException>().is_some(),
+ e.is_instanceof::<UnexpectedValueException>(),
"expected UnexpectedValueException, got: {e}"
);
assert!(