diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-06-20 15:37:24 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-06-20 15:45:19 +0900 |
| commit | 1b38bdb5a1de127ca8040f5a132d08c73ccb3c67 (patch) | |
| tree | 71cd969054fa56845d737abf4e55e10a12c378a0 /crates/shirabe-php-shim/src/lib.rs | |
| parent | b7c3981fd60662cdf500aaf1a7e49a77b967968d (diff) | |
| download | php-shirabe-1b38bdb5a1de127ca8040f5a132d08c73ccb3c67.tar.gz php-shirabe-1b38bdb5a1de127ca8040f5a132d08c73ccb3c67.tar.zst php-shirabe-1b38bdb5a1de127ca8040f5a132d08c73ccb3c67.zip | |
refactor(console): propagate getComposer's exit(1) as ExitException
Composer's Application::getComposer() calls exit(1) when a required
Composer instance fails to build under areExceptionsCaught(). Replace the
deep std::process::exit with a php-shim ExitException that mirrors PHP's
`exit` construct: it bypasses parent::doRun()'s catch and Symfony's
renderThrowable (excluded at both broad catches), so the already-written
plain error message is not re-rendered and the process exits with code 1.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe-php-shim/src/lib.rs')
| -rw-r--r-- | crates/shirabe-php-shim/src/lib.rs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/crates/shirabe-php-shim/src/lib.rs b/crates/shirabe-php-shim/src/lib.rs index 4f7b4d2..949c5e2 100644 --- a/crates/shirabe-php-shim/src/lib.rs +++ b/crates/shirabe-php-shim/src/lib.rs @@ -3150,6 +3150,25 @@ pub fn exit(status: i64) -> ! { std::process::exit(status as i32); } +/// Models PHP's `exit`/`die` language construct propagated as a recoverable error so the actual +/// process termination happens at a single top-level site instead of deep in the call stack. +/// +/// Like PHP's `exit`, this must NOT be caught by ported `try`/`catch` blocks: any broad catch on +/// the propagation path has to re-raise it untouched, and only the outermost handler converts it +/// into the process exit code. +#[derive(Debug)] +pub struct ExitException { + pub code: i64, +} + +impl std::fmt::Display for ExitException { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "exit({})", self.code) + } +} + +impl std::error::Error for ExitException {} + pub fn is_resource_value(_resource: &PhpResource) -> bool { true } |
