aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/command
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-08 22:37:08 +0900
committernsfisis <nsfisis@gmail.com>2026-08-09 00:14:09 +0900
commitc74f4314853c0e7283691fdd4d0dec27c1199537 (patch)
tree2dd1c0a593498da1ac38cd1e61a92cce6dc78aa5 /crates/shirabe/src/command
parentf4cad2123b2af0de72bda4ce039e16e74f163f4e (diff)
downloadphp-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/command')
-rw-r--r--crates/shirabe/src/command/exec_command.rs9
-rw-r--r--crates/shirabe/src/command/global_command.rs8
-rw-r--r--crates/shirabe/src/command/require_command.rs12
3 files changed, 19 insertions, 10 deletions
diff --git a/crates/shirabe/src/command/exec_command.rs b/crates/shirabe/src/command/exec_command.rs
index a67c234e..61391117 100644
--- a/crates/shirabe/src/command/exec_command.rs
+++ b/crates/shirabe/src/command/exec_command.rs
@@ -220,10 +220,11 @@ impl Command for ExecCommand {
&& getcwd().as_deref() != Some(iwd.as_str())
{
chdir(iwd).map_err(|e| {
- RuntimeException::new(format!(
- "Could not switch back to working directory \"{}\"",
- iwd
- ))
+ RuntimeException::with_code_and_previous(
+ format!("Could not switch back to working directory \"{}\"", iwd),
+ 0,
+ Some(std::sync::Arc::new(e)),
+ )
})?;
}
diff --git a/crates/shirabe/src/command/global_command.rs b/crates/shirabe/src/command/global_command.rs
index 78b6f3e6..df9798a3 100644
--- a/crates/shirabe/src/command/global_command.rs
+++ b/crates/shirabe/src/command/global_command.rs
@@ -90,8 +90,12 @@ impl GlobalCommand {
}
}
- chdir(&home).map_err(|_e| {
- RuntimeException::new(format!("Could not switch to home directory \"{}\"", home))
+ chdir(&home).map_err(|e| {
+ RuntimeException::with_code_and_previous(
+ format!("Could not switch to home directory \"{}\"", home),
+ 0,
+ Some(std::sync::Arc::new(e)),
+ )
})?;
if !quiet {
diff --git a/crates/shirabe/src/command/require_command.rs b/crates/shirabe/src/command/require_command.rs
index 84b4a6e4..88916175 100644
--- a/crates/shirabe/src/command/require_command.rs
+++ b/crates/shirabe/src/command/require_command.rs
@@ -977,10 +977,14 @@ impl Command for RequireCommand {
if self.newly_created.get() {
self.revert_composer_file();
- return Err(RuntimeException::new(format!(
- "No composer.json present in the current directory ({}), this may be the cause of the following exception.",
- self.file.borrow()
- ))
+ return Err(RuntimeException::with_code_and_previous(
+ format!(
+ "No composer.json present in the current directory ({}), this may be the cause of the following exception.",
+ self.file.borrow()
+ ),
+ 0,
+ Some(std::sync::Arc::new(e)),
+ )
.into());
}