aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/downloader
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-06-03 00:57:47 +0900
committernsfisis <nsfisis@gmail.com>2026-06-03 01:13:55 +0900
commit8888e4b8bfeb41e4edd45ab47db8a293e93ded3f (patch)
treeeb37ebb6dc44b33d1bcf843ce0228e24cd58d221 /crates/shirabe/src/downloader
parent37f10618689c55d651028487c39988fedcb593ea (diff)
downloadphp-shirabe-8888e4b8bfeb41e4edd45ab47db8a293e93ded3f.tar.gz
php-shirabe-8888e4b8bfeb41e4edd45ab47db8a293e93ded3f.tar.zst
php-shirabe-8888e4b8bfeb41e4edd45ab47db8a293e93ded3f.zip
feat(downloader,repository): wire exception instanceof downcasts via anyhow
Resolve the PHP try/catch instanceof checks that select on exception type: TransportException-only catches in RepositorySet, SvnDriver and JsonFile; the RuntimeException/IrrecoverableDownloadException handleError closure and the RuntimeException update-retry catch in DownloadManager. Each uses anyhow::Error::downcast_ref and reads the exception's message field directly (Display is todo\!() on the shim exceptions). PHPUnit\Framework\Exception checks in VcsDownloader are documented as intentionally always-false since the test framework is out of scope. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/downloader')
-rw-r--r--crates/shirabe/src/downloader/download_manager.rs27
-rw-r--r--crates/shirabe/src/downloader/vcs_downloader.rs15
2 files changed, 28 insertions, 14 deletions
diff --git a/crates/shirabe/src/downloader/download_manager.rs b/crates/shirabe/src/downloader/download_manager.rs
index 33a555a..8131bcf 100644
--- a/crates/shirabe/src/downloader/download_manager.rs
+++ b/crates/shirabe/src/downloader/download_manager.rs
@@ -246,21 +246,25 @@ impl DownloadManager {
Ok(r) => r,
Err(e) => {
// PHP closure handleError: rethrow if not RuntimeException or if IrrecoverableDownloadException
- // TODO(phase-b): downcast for instanceof checks
- let is_runtime: bool = todo!("e instanceof RuntimeException");
- let is_irrecoverable: bool =
- todo!("e instanceof IrrecoverableDownloadException");
+ let is_runtime = e.downcast_ref::<RuntimeException>().is_some();
+ let is_irrecoverable =
+ e.downcast_ref::<IrrecoverableDownloadException>().is_some();
if is_runtime && !is_irrecoverable {
if sources.is_empty() {
return Err(e);
}
+ let message = e
+ .downcast_ref::<RuntimeException>()
+ .unwrap()
+ .message
+ .clone();
self.io.write_error3(
&format!(
" <warning>Failed to download {} from {}: {}</warning>",
package.get_pretty_name(),
source,
- e,
+ message,
),
true,
io_interface::NORMAL,
@@ -367,13 +371,20 @@ impl DownloadManager {
{
Ok(p) => return Ok(p),
Err(e) => {
- // TODO(phase-b): downcast to RuntimeException
- let _re: &RuntimeException = todo!("downcast e to RuntimeException");
+ // PHP catches only \RuntimeException; other exceptions propagate uncaught.
+ if e.downcast_ref::<RuntimeException>().is_none() {
+ return Err(e);
+ }
if !self.io.is_interactive() {
return Err(e);
}
+ let message = e
+ .downcast_ref::<RuntimeException>()
+ .unwrap()
+ .message
+ .clone();
self.io.write_error3(
- &format!("<error> Update failed ({})</error>", e,),
+ &format!("<error> Update failed ({})</error>", message),
true,
io_interface::NORMAL,
);
diff --git a/crates/shirabe/src/downloader/vcs_downloader.rs b/crates/shirabe/src/downloader/vcs_downloader.rs
index b09841e..c3a1611 100644
--- a/crates/shirabe/src/downloader/vcs_downloader.rs
+++ b/crates/shirabe/src/downloader/vcs_downloader.rs
@@ -149,8 +149,9 @@ pub trait VcsDownloader:
match attempt {
Ok(promise) => return Ok(promise),
Err(e) => {
- // rethrow phpunit exceptions to avoid hard to debug bug failures
- // TODO(phase-b): downcast to PHPUnit\Framework\Exception
+ // rethrow phpunit exceptions to avoid hard to debug bug failures.
+ // PHPUnit\Framework\Exception is out of scope (the test framework is not
+ // ported), so this instanceof check is always false.
let is_phpunit_exception = false;
if is_phpunit_exception {
return Err(e);
@@ -265,8 +266,9 @@ pub trait VcsDownloader:
match attempt {
Ok(_) => break,
Err(e) => {
- // rethrow phpunit exceptions to avoid hard to debug bug failures
- // TODO(phase-b): downcast to PHPUnit\Framework\Exception
+ // rethrow phpunit exceptions to avoid hard to debug bug failures.
+ // PHPUnit\Framework\Exception is out of scope (the test framework is not
+ // ported), so this instanceof check is always false.
let is_phpunit_exception = false;
if is_phpunit_exception {
return Err(e);
@@ -344,8 +346,9 @@ pub trait VcsDownloader:
break;
}
Err(e) => {
- // rethrow phpunit exceptions to avoid hard to debug bug failures
- // TODO(phase-b): downcast to PHPUnit\Framework\Exception
+ // rethrow phpunit exceptions to avoid hard to debug bug failures.
+ // PHPUnit\Framework\Exception is out of scope (the test framework is not
+ // ported), so this instanceof check is always false.
let is_phpunit_exception = false;
if is_phpunit_exception {
return Err(e);