diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-08-08 22:37:08 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-08-09 00:14:09 +0900 |
| commit | c74f4314853c0e7283691fdd4d0dec27c1199537 (patch) | |
| tree | 2dd1c0a593498da1ac38cd1e61a92cce6dc78aa5 /crates/shirabe/src/repository | |
| parent | f4cad2123b2af0de72bda4ce039e16e74f163f4e (diff) | |
| download | php-shirabe-c74f4314853c0e7283691fdd4d0dec27c1199537.tar.gz php-shirabe-c74f4314853c0e7283691fdd4d0dec27c1199537.tar.zst php-shirabe-c74f4314853c0e7283691fdd4d0dec27c1199537.zip | |
fix(exception): carry PHP's $previous through the ported throw sites
Composer hands the exception it caught to the one it throws in its place,
so `getPrevious()` reaches the cause and Application's renderer prints the
whole chain. Every ported site dropped it, because the flat exception
structs had nowhere to put one. `AnyThrowable::into_previous` turns the
caught error into that argument, and the 13 sites now pass it.
`getCode()` came along for the ride at the four sites that derive the new
exception's code from the caught one (PharArchiver, ArrayLoader x2), and
ComposerRepository's message now names the caught exception's class
instead of the literal "Exception".
GitHubDriver::attemptCloneFallback took the previous exception's message
and appended it to its own, which no `\RuntimeException('Fallback to git
driver disabled')` in Composer ever says; it now chains it instead.
Git::syncMirror restores what PHP's `finally` does to an exception in
flight: the `git remote set-url` that scrubs credentials back out of the
URL runs in a `finally`, and when it fails PHP propagates *its* exception
over the one already leaving, chaining the displaced one as previous. The
port discarded the finally's result, so a failure to scrub the URL was
reported as a successful mirror sync. `AnyThrowable::set_previous`
models the engine-level chaining.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/repository')
4 files changed, 34 insertions, 25 deletions
diff --git a/crates/shirabe/src/repository/artifact_repository.rs b/crates/shirabe/src/repository/artifact_repository.rs index 2d16f137..75ad134b 100644 --- a/crates/shirabe/src/repository/artifact_repository.rs +++ b/crates/shirabe/src/repository/artifact_repository.rs @@ -224,11 +224,15 @@ impl ArtifactRepository { .unwrap_or_default(); match self.loader.load(cfg, None) { Ok(package) => Ok(Some(package)), - Err(exception) => Err(UnexpectedValueException::new(format!( - "Failed loading package in {}: {}", - pathname, exception - )) - .into()), + Err(exception) => { + let message = format!("Failed loading package in {}: {}", pathname, exception); + Err(UnexpectedValueException::with_code_and_previous( + message, + 0, + Some(std::sync::Arc::new(exception)), + ) + .into()) + } } } } diff --git a/crates/shirabe/src/repository/composer_repository.rs b/crates/shirabe/src/repository/composer_repository.rs index 5371c2c3..b53374aa 100644 --- a/crates/shirabe/src/repository/composer_repository.rs +++ b/crates/shirabe/src/repository/composer_repository.rs @@ -40,9 +40,9 @@ use shirabe_external_packages::composer::pcre::{CaptureKey, Preg}; use shirabe_metadata_minifier::MetadataMinifier; use shirabe_php_shim::Catch as _; use shirabe_php_shim::{ - CmpOp, InvalidArgumentException, LogicException, PHP_EOL, PhpMixed, RuntimeException, - UnexpectedValueException, extension_loaded, hash, http_build_query, json_decode, parse_url_all, - php_regex, realpath, strtolower, strtr, urlencode, var_export, + AnyThrowable, CmpOp, InvalidArgumentException, LogicException, PHP_EOL, PhpMixed, + RuntimeException, UnexpectedValueException, extension_loaded, hash, http_build_query, + json_decode, parse_url_all, php_regex, realpath, strtolower, strtr, urlencode, var_export, }; use shirabe_semver::CompilingMatcher; use shirabe_semver::constraint::AnyConstraint; @@ -2695,17 +2695,21 @@ impl ComposerRepository { })(); result.map_err(|e| { - RuntimeException::new(format!( + let message = format!( "Could not load packages in {}{}: [{}] {}", self.get_repo_name(), source .as_ref() .map(|s| format!(" from {}", s)) .unwrap_or_default(), - "Exception", + AnyThrowable::of(e.as_ref()).map_or_else( + || "Exception".to_string(), + shirabe_php_shim::PhpClass::php_class_name, + ), e - )) - .into() + ); + RuntimeException::with_code_and_previous(message, 0, Some(std::sync::Arc::new(e))) + .into() }) } diff --git a/crates/shirabe/src/repository/path_repository.rs b/crates/shirabe/src/repository/path_repository.rs index 313fc75e..46b7f95f 100644 --- a/crates/shirabe/src/repository/path_repository.rs +++ b/crates/shirabe/src/repository/path_repository.rs @@ -350,10 +350,11 @@ impl PathRepository { self.inner .add_package(self.loader.load(package.clone(), None).map_err(|e| { - RuntimeException::new(format!( - "Failed loading the package in {}", - composer_file_path - )) + RuntimeException::with_code_and_previous( + format!("Failed loading the package in {}", composer_file_path), + 0, + Some(std::sync::Arc::new(e)), + ) })?); } diff --git a/crates/shirabe/src/repository/vcs/github_driver.rs b/crates/shirabe/src/repository/vcs/github_driver.rs index 72bcc8ae..ffdf04ec 100644 --- a/crates/shirabe/src/repository/vcs/github_driver.rs +++ b/crates/shirabe/src/repository/vcs/github_driver.rs @@ -1038,7 +1038,7 @@ impl GitHubDriver { } if !self.inner.io.is_interactive() { - self.attempt_clone_fallback(Some(&e)) + self.attempt_clone_fallback(Some(std::sync::Arc::new((*e).into()))) .map_err(|err| TransportException::new(err.to_string(), 0))?; return Ok(Response::new( @@ -1090,7 +1090,7 @@ impl GitHubDriver { } if !self.inner.io.is_interactive() && fetching_repo_data { - self.attempt_clone_fallback(Some(&e)) + self.attempt_clone_fallback(Some(std::sync::Arc::new((*e).into()))) .map_err(|err| TransportException::new(err.to_string(), 0))?; return Ok(Response::new( @@ -1177,7 +1177,7 @@ impl GitHubDriver { } Err(e) => { if e.get_code() == 499 { - self.attempt_clone_fallback(Some(&e))?; + self.attempt_clone_fallback(Some(std::sync::Arc::new((*e).into())))?; } else { return Err((*e).into()); } @@ -1227,14 +1227,14 @@ impl GitHubDriver { /// @throws \RuntimeException pub(crate) fn attempt_clone_fallback( &mut self, - e: Option<&TransportException>, + e: Option<std::sync::Arc<anyhow::Error>>, ) -> anyhow::Result<bool> { if !self.allow_git_fallback { - return Err(RuntimeException::new(format!( - "Fallback to git driver disabled{}", - e.map(|e| format!(": {}", e.get_message())) - .unwrap_or_default() - )) + return Err(RuntimeException::with_code_and_previous( + "Fallback to git driver disabled".to_string(), + 0, + e, + ) .into()); } |
