From 8888e4b8bfeb41e4edd45ab47db8a293e93ded3f Mon Sep 17 00:00:00 2001 From: nsfisis Date: Wed, 3 Jun 2026 00:57:47 +0900 Subject: 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) --- crates/shirabe/src/json/json_file.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'crates/shirabe/src/json') diff --git a/crates/shirabe/src/json/json_file.rs b/crates/shirabe/src/json/json_file.rs index 2450b0a..364c2b9 100644 --- a/crates/shirabe/src/json/json_file.rs +++ b/crates/shirabe/src/json/json_file.rs @@ -138,10 +138,15 @@ impl JsonFile { })() { Ok(j) => j, Err(e) => { - // TODO(phase-b): downcast e to TransportException to match the specific catch - let _te: &TransportException = todo!("downcast e to TransportException"); - // PHP: throw new \RuntimeException($e->getMessage(), 0, $e); (rethrow wrapped) - // PHP fallback: throw new \RuntimeException('Could not read '.$this->path."\n\n".$e->getMessage()); + // TransportException keeps its message verbatim; any other exception is wrapped + // with the "Could not read" prefix. + if let Some(te) = e.downcast_ref::() { + return Err(RuntimeException { + message: te.message.clone(), + code: 0, + } + .into()); + } return Err(RuntimeException { message: format!("Could not read {}\n\n{}", self.path, e), code: 0, -- cgit v1.3.1