aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/downloader
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-18 07:18:07 +0900
committernsfisis <nsfisis@gmail.com>2026-08-18 07:18:07 +0900
commit6a7e64d04a8b0ad932169df43e2d93efe8ceedf8 (patch)
treef74bca82b226fde11c820ba3988e094a49073940 /crates/shirabe/src/downloader
parentbed0cd33ca32b95aed9d65891f97649a6f9d0069 (diff)
downloadphp-shirabe-6a7e64d04a8b0ad932169df43e2d93efe8ceedf8.tar.gz
php-shirabe-6a7e64d04a8b0ad932169df43e2d93efe8ceedf8.tar.zst
php-shirabe-6a7e64d04a8b0ad932169df43e2d93efe8ceedf8.zip
fix: propagate ported exceptions instead of flattening them
`ProcessExecutor::execute_args` existed only to turn `execute`'s `anyhow::Result` into an exit code of 1, so every one of its ~87 call sites silently took the "command failed" branch on an error PHP would have thrown. It is gone; callers use `execute` and propagate with `?`. Where the enclosing function had no `Result` to propagate into, its signature grew one, up to and including `Git::get_version`, `Svn::binary_version`, `GitHub`/`GitLab`/`Bitbucket::authorize_oauth`, `InitCommand::get_git_config` and `DiagnoseCommand::check_git`. The VCS drivers had the same problem in the other direction: their `get_contents` returned `Result<Response, Box<TransportException>>`, a type too narrow for the PHP method, which lets any Throwable out of the `catch (TransportException $e)` block. Every non-transport error was therefore rewritten into a `TransportException` with code 0, which the callers switch on. They now return `anyhow::Result<Result<Response, Box<TransportException>>>`: the outer `Result` carries what PHP does not catch, the inner one the exception the drivers handle. That signature also restores `GitLabDriver::getContents`: the 400/401 `TransportException`s it raises to force authentication are thrown inside its own `try` block and handled by its own `catch`, but the port returned them straight to the caller, so the authentication flow behind them never ran. `impl_php_exception!` gains `From<Box<$ty>> for anyhow::Error` so a caught exception can be re-propagated with `?`. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/downloader')
-rw-r--r--crates/shirabe/src/downloader/fossil_downloader.rs4
-rw-r--r--crates/shirabe/src/downloader/git_downloader.rs94
-rw-r--r--crates/shirabe/src/downloader/hg_downloader.rs14
-rw-r--r--crates/shirabe/src/downloader/svn_downloader.rs14
4 files changed, 64 insertions, 62 deletions
diff --git a/crates/shirabe/src/downloader/fossil_downloader.rs b/crates/shirabe/src/downloader/fossil_downloader.rs
index 96886ca0..d04529b3 100644
--- a/crates/shirabe/src/downloader/fossil_downloader.rs
+++ b/crates/shirabe/src/downloader/fossil_downloader.rs
@@ -254,11 +254,11 @@ impl ChangeReportInterface for FossilDownloader {
}
let mut output = String::new();
- self.inner.process.borrow_mut().execute_args(
+ self.inner.process.borrow_mut().execute(
&["fossil".to_string(), "changes".to_string()],
&mut output,
shirabe_php_shim::realpath(path).as_deref(),
- );
+ )?;
let output = output.trim().to_string();
diff --git a/crates/shirabe/src/downloader/git_downloader.rs b/crates/shirabe/src/downloader/git_downloader.rs
index 2d506fdf..cf1bfd82 100644
--- a/crates/shirabe/src/downloader/git_downloader.rs
+++ b/crates/shirabe/src/downloader/git_downloader.rs
@@ -82,7 +82,7 @@ impl GitDownloader {
.inner
.process
.borrow_mut()
- .execute_args(&command, &mut output, Some(&path))
+ .execute(&command, &mut output, Some(&path))?
!= 0
{
return Err(RuntimeException::new(format!(
@@ -173,11 +173,11 @@ impl GitDownloader {
"--".to_string(),
];
let mut output = String::new();
- if self.inner.process.borrow_mut().execute_args(
+ if self.inner.process.borrow_mut().execute(
&command,
&mut output,
Some(&path),
- ) != 0
+ )? != 0
{
return Err(RuntimeException::new(format!(
"Failed to execute {}\n\n{}",
@@ -201,11 +201,11 @@ impl GitDownloader {
// remotes and then try again as outdated remotes can sometimes cause false-positives
if unpushed_changes.is_some() && i == 0 {
let mut output = String::new();
- self.inner.process.borrow_mut().execute_args(
+ self.inner.process.borrow_mut().execute(
&["git".to_string(), "fetch".to_string(), "--all".to_string()],
&mut output,
Some(&path),
- );
+ )?;
// update list of refs after fetching
let command = vec![
@@ -219,7 +219,7 @@ impl GitDownloader {
.inner
.process
.borrow_mut()
- .execute_args(&command, &mut output, Some(&path))
+ .execute(&command, &mut output, Some(&path))?
!= 0
{
return Err(RuntimeException::new(format!(
@@ -288,11 +288,11 @@ impl GitDownloader {
let mut branches: Option<String> = None;
{
let mut output = String::new();
- if self.inner.process.borrow_mut().execute_args(
+ if self.inner.process.borrow_mut().execute(
&["git".to_string(), "branch".to_string(), "-r".to_string()],
&mut output,
Some(path),
- ) == 0
+ )? == 0
{
branches = Some(output);
}
@@ -328,14 +328,14 @@ impl GitDownloader {
self.inner
.process
.borrow_mut()
- .execute_args(&command1, &mut output, Some(path))
+ .execute(&command1, &mut output, Some(path))?
== 0;
let ok2 = if ok1 {
let mut output = String::new();
self.inner
.process
.borrow_mut()
- .execute_args(&command2, &mut output, Some(path))
+ .execute(&command2, &mut output, Some(path))?
== 0
} else {
false
@@ -388,25 +388,25 @@ impl GitDownloader {
self.inner
.process
.borrow_mut()
- .execute_args(&command, &mut output, Some(path))
+ .execute(&command, &mut output, Some(path))?
== 0;
let ok_fallback = if !ok_command {
let mut output = String::new();
- self.inner.process.borrow_mut().execute_args(
+ self.inner.process.borrow_mut().execute(
&fallback_command,
&mut output,
Some(path),
- ) == 0
+ )? == 0
} else {
false
};
let ok_reset = if ok_command || ok_fallback {
let mut output = String::new();
- self.inner.process.borrow_mut().execute_args(
- &reset_command,
- &mut output,
- Some(path),
- ) == 0
+ self.inner
+ .process
+ .borrow_mut()
+ .execute(&reset_command, &mut output, Some(path))?
+ == 0
} else {
false
};
@@ -431,14 +431,14 @@ impl GitDownloader {
self.inner
.process
.borrow_mut()
- .execute_args(&command1, &mut output, Some(path))
+ .execute(&command1, &mut output, Some(path))?
== 0;
let ok2 = if ok1 {
let mut output = String::new();
self.inner
.process
.borrow_mut()
- .execute_args(&command2, &mut output, Some(path))
+ .execute(&command2, &mut output, Some(path))?
== 0
} else {
false
@@ -482,9 +482,9 @@ impl GitDownloader {
.into())
}
- fn update_origin_url(&self, path: &str, url: &str) {
+ fn update_origin_url(&self, path: &str, url: &str) -> anyhow::Result<()> {
let mut output = String::new();
- self.inner.process.borrow_mut().execute_args(
+ self.inner.process.borrow_mut().execute(
&[
"git".to_string(),
"remote".to_string(),
@@ -495,11 +495,11 @@ impl GitDownloader {
],
&mut output,
Some(path),
- );
- self.set_push_url(path, url);
+ )?;
+ self.set_push_url(path, url)
}
- fn set_push_url(&self, path: &str, url: &str) {
+ fn set_push_url(&self, path: &str, url: &str) -> anyhow::Result<()> {
// set push url for github projects
if let Some(match_) = preg_match(
format!(
@@ -529,30 +529,32 @@ impl GitDownloader {
self.inner
.process
.borrow_mut()
- .execute_args(&cmd, &mut ignored_output, Some(path));
+ .execute(&cmd, &mut ignored_output, Some(path))?;
}
+
+ Ok(())
}
/// @throws \RuntimeException
async fn discard_changes(&self, path: &str) -> anyhow::Result<Option<PhpMixed>> {
let path = self.normalize_path(path);
let mut output = String::new();
- if self.inner.process.borrow_mut().execute_args(
+ if self.inner.process.borrow_mut().execute(
&["git".to_string(), "clean".to_string(), "-df".to_string()],
&mut output,
Some(&path),
- ) != 0
+ )? != 0
{
return Err(
RuntimeException::new(format!("Could not reset changes\n\n:{}", output)).into(),
);
}
let mut output = String::new();
- if self.inner.process.borrow_mut().execute_args(
+ if self.inner.process.borrow_mut().execute(
&["git".to_string(), "reset".to_string(), "--hard".to_string()],
&mut output,
Some(&path),
- ) != 0
+ )? != 0
{
return Err(
RuntimeException::new(format!("Could not reset changes\n\n:{}", output)).into(),
@@ -568,7 +570,7 @@ impl GitDownloader {
async fn stash_changes(&self, path: &str) -> anyhow::Result<Option<PhpMixed>> {
let path = self.normalize_path(path);
let mut output = String::new();
- if self.inner.process.borrow_mut().execute_args(
+ if self.inner.process.borrow_mut().execute(
&[
"git".to_string(),
"stash".to_string(),
@@ -576,7 +578,7 @@ impl GitDownloader {
],
&mut output,
Some(&path),
- ) != 0
+ )? != 0
{
return Err(
RuntimeException::new(format!("Could not stash changes\n\n:{}", output)).into(),
@@ -592,11 +594,11 @@ impl GitDownloader {
fn view_diff(&self, path: &str) -> anyhow::Result<()> {
let path = self.normalize_path(path);
let mut output = String::new();
- if self.inner.process.borrow_mut().execute_args(
+ if self.inner.process.borrow_mut().execute(
&["git".to_string(), "diff".to_string(), "HEAD".to_string()],
&mut output,
Some(&path),
- ) != 0
+ )? != 0
{
return Err(
RuntimeException::new(format!("Could not view diff\n\n:{}", output)).into(),
@@ -700,7 +702,7 @@ impl ChangeReportInterface for GitDownloader {
.inner
.process
.borrow_mut()
- .execute_args(&command, &mut output, Some(path))
+ .execute(&command, &mut output, Some(path))?
!= 0
{
return Err(RuntimeException::new(format!(
@@ -772,7 +774,7 @@ impl VcsDownloader for GitDownloader {
.unwrap_or(""),
preg_replace(r"{[^a-z0-9.]}i", "-", &Url::sanitize(url.to_string())),
);
- let git_version = GitUtil::get_version(&self.inner.process);
+ let git_version = GitUtil::get_version(&self.inner.process)?;
// --dissociate option is only available since git 2.3.0-rc0
if git_version.is_some()
@@ -1026,7 +1028,7 @@ impl VcsDownloader for GitDownloader {
self.inner.io.write_error3(&msg, true, io_interface::NORMAL);
let mut output = String::new();
- if self.inner.process.borrow_mut().execute_args(
+ if self.inner.process.borrow_mut().execute(
&[
"git".to_string(),
"rev-parse".to_string(),
@@ -1036,7 +1038,7 @@ impl VcsDownloader for GitDownloader {
],
&mut output,
Some(&path),
- ) != 0
+ )? != 0
{
let commands = vec![
vec![
@@ -1089,11 +1091,11 @@ impl VcsDownloader for GitDownloader {
let mut update_origin_url = false;
let mut output = String::new();
- if self.inner.process.borrow_mut().execute_args(
+ if self.inner.process.borrow_mut().execute(
&["git".to_string(), "remote".to_string(), "-v".to_string()],
&mut output,
Some(&path),
- ) == 0
+ )? == 0
&& let Some(origin_match) =
preg_match(php_regex!(r"{^origin\s+(?P<url>\S+)}m"), &output)
&& let Some(composer_match) =
@@ -1287,11 +1289,11 @@ impl VcsDownloader for GitDownloader {
io_interface::NORMAL,
);
let mut output = String::new();
- if self.inner.process.borrow_mut().execute_args(
+ if self.inner.process.borrow_mut().execute(
&["git".to_string(), "stash".to_string(), "pop".to_string()],
&mut output,
Some(&path),
- ) != 0
+ )? != 0
{
return Err(RuntimeException::new(format!(
"Failed to apply stashed changes:\n\n{}",
@@ -1316,15 +1318,15 @@ impl VcsDownloader for GitDownloader {
"--format=%h - %an: %s".to_string(),
format!("{}..{}", from_reference, to_reference),
];
- args.extend(GitUtil::get_no_show_signature_flags(&self.inner.process));
- let command = GitUtil::build_rev_list_command(&self.inner.process, args);
+ args.extend(GitUtil::get_no_show_signature_flags(&self.inner.process)?);
+ let command = GitUtil::build_rev_list_command(&self.inner.process, args)?;
let mut output = String::new();
if self
.inner
.process
.borrow_mut()
- .execute_args(&command, &mut output, Some(&path))
+ .execute(&command, &mut output, Some(&path))?
!= 0
{
return Err(RuntimeException::new(format!(
@@ -1335,7 +1337,7 @@ impl VcsDownloader for GitDownloader {
.into());
}
- Ok(GitUtil::parse_rev_list_output(&output, &self.inner.process))
+ GitUtil::parse_rev_list_output(&output, &self.inner.process)
}
fn has_metadata_repository(&self, path: &str) -> bool {
diff --git a/crates/shirabe/src/downloader/hg_downloader.rs b/crates/shirabe/src/downloader/hg_downloader.rs
index dfd25618..a36b4c57 100644
--- a/crates/shirabe/src/downloader/hg_downloader.rs
+++ b/crates/shirabe/src/downloader/hg_downloader.rs
@@ -63,7 +63,7 @@ impl VcsDownloader for HgDownloader {
_url: &str,
_prev_package: Option<PackageInterfaceHandle>,
) -> anyhow::Result<Option<PhpMixed>> {
- if HgUtils::get_version(&self.inner.process).is_none() {
+ if HgUtils::get_version(&self.inner.process)?.is_none() {
return Err(RuntimeException::new(
"hg was not found in your PATH, skipping source download".to_string(),
)
@@ -104,11 +104,11 @@ impl VcsDownloader for HgDownloader {
package.get_source_reference().unwrap_or_default(),
];
let mut ignored_output = String::new();
- if self.inner.process.borrow_mut().execute_args(
+ if self.inner.process.borrow_mut().execute(
&command,
&mut ignored_output,
shirabe_php_shim::realpath(path).as_deref(),
- ) != 0
+ )? != 0
{
return Err(RuntimeException::new(format!(
"Failed to execute {}\n\n{}",
@@ -182,11 +182,11 @@ impl VcsDownloader for HgDownloader {
];
let mut output = String::new();
- if self.inner.process.borrow_mut().execute_args(
+ if self.inner.process.borrow_mut().execute(
&command,
&mut output,
shirabe_php_shim::realpath(path).as_deref(),
- ) != 0
+ )? != 0
{
return Err(RuntimeException::new(format!(
"Failed to execute {}\n\n{}",
@@ -215,11 +215,11 @@ impl ChangeReportInterface for HgDownloader {
}
let mut output = String::new();
- self.inner.process.borrow_mut().execute_args(
+ self.inner.process.borrow_mut().execute(
&["hg".to_string(), "st".to_string()],
&mut output,
shirabe_php_shim::realpath(path).as_deref(),
- );
+ )?;
let output = output.trim().to_string();
diff --git a/crates/shirabe/src/downloader/svn_downloader.rs b/crates/shirabe/src/downloader/svn_downloader.rs
index 93b860f0..8c062320 100644
--- a/crates/shirabe/src/downloader/svn_downloader.rs
+++ b/crates/shirabe/src/downloader/svn_downloader.rs
@@ -69,11 +69,11 @@ impl SvnDownloader {
async fn discard_changes(&self, path: &str) -> anyhow::Result<Option<PhpMixed>> {
let mut output = String::new();
- if self.inner.process.borrow_mut().execute_args(
+ if self.inner.process.borrow_mut().execute(
["svn", "revert", "-R", "."].map(|s| s.to_string()).as_ref(),
&mut output,
Some(path),
- ) != 0
+ )? != 0
{
return Err(RuntimeException::new(format!(
"Could not reset changes\n\n:{}",
@@ -139,7 +139,7 @@ impl VcsDownloader for SvnDownloader {
self.inner.config.clone(),
Some(self.inner.process.clone()),
);
- if util.binary_version().is_none() {
+ if util.binary_version()?.is_none() {
return Err(RuntimeException::new(
"svn was not found in your PATH, skipping source download".to_string(),
)
@@ -217,7 +217,7 @@ impl VcsDownloader for SvnDownloader {
);
let mut flags: Vec<String> = vec![];
if version_compare(
- &util.binary_version().unwrap_or_default(),
+ &util.binary_version()?.unwrap_or_default(),
"1.7.0",
CmpOp::Ge,
) {
@@ -370,7 +370,7 @@ impl VcsDownloader for SvnDownloader {
.inner
.process
.borrow_mut()
- .execute_args(&command, &mut output, Some(path))
+ .execute(&command, &mut output, Some(path))?
!= 0
{
return Err(RuntimeException::new(format!(
@@ -444,13 +444,13 @@ impl ChangeReportInterface for SvnDownloader {
}
let mut output = String::new();
- self.inner.process.borrow_mut().execute_args(
+ self.inner.process.borrow_mut().execute(
["svn", "status", "--ignore-externals"]
.map(|s| s.to_string())
.as_ref(),
&mut output,
Some(path),
- );
+ )?;
Ok(if preg_is_match(php_regex!("{^ *[^X ] +}m"), &output) {
Some(output)