From b62d937331860b5cf17737c9f6be8a015bda102c Mon Sep 17 00:00:00 2001 From: nsfisis Date: Fri, 5 Jun 2026 01:52:51 +0900 Subject: refactor(downloader): return Result from GitDownloader::view_diff PHP's viewDiff returns void but throws RuntimeException when git diff fails. Model it as Result<()> and propagate via ? at the single caller instead of panicking. Co-Authored-By: Claude Opus 4.8 --- crates/shirabe/src/downloader/git_downloader.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'crates') diff --git a/crates/shirabe/src/downloader/git_downloader.rs b/crates/shirabe/src/downloader/git_downloader.rs index 26ff4aa..bc8db6d 100644 --- a/crates/shirabe/src/downloader/git_downloader.rs +++ b/crates/shirabe/src/downloader/git_downloader.rs @@ -618,7 +618,7 @@ impl GitDownloader { } /// @throws \RuntimeException - pub(crate) fn view_diff(&mut self, path: &str) { + pub(crate) fn view_diff(&mut self, path: &str) -> Result<()> { let path = self.normalize_path(path); let mut output = String::new(); if self.inner.process.borrow_mut().execute_args( @@ -627,13 +627,18 @@ impl GitDownloader { Some(path.clone()), ) != 0 { - // TODO(phase-b): cannot throw from non-Result fn; bubble error via Result later - panic!("{}", format!("Could not view diff\n\n:{}", output)); + return Err(RuntimeException { + message: format!("Could not view diff\n\n:{}", output), + code: 0, + } + .into()); } self.inner .io .write_error3(&output, true, io_interface::NORMAL); + + Ok(()) } pub(crate) fn normalize_path(&self, path: &str) -> String { @@ -1283,7 +1288,7 @@ impl VcsDownloader for GitDownloader { .write_error3(&changes.join("\n"), true, io_interface::NORMAL); } Some("d") => { - self.view_diff(&path); + self.view_diff(&path)?; } _ => { // case '?': default: -- cgit v1.3.1