From ce6192f1cfaac63457b173f573ada661a4665bfb Mon Sep 17 00:00:00 2001 From: nsfisis Date: Thu, 6 Aug 2026 04:01:58 +0900 Subject: feat(console): override TransportException's code in doRun PHP mutates the caught exception's protected $code via ReflectionProperty. The port takes ownership of the exception through anyhow's downcast, writes ERROR_TRANSPORT_EXCEPTION into its public code field and re-wraps it, so no reflection equivalent is needed. Co-Authored-By: Claude Opus 5 (1M context) --- crates/shirabe/src/console/application.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'crates/shirabe/src/console/application.rs') diff --git a/crates/shirabe/src/console/application.rs b/crates/shirabe/src/console/application.rs index 19317363..c6674c77 100644 --- a/crates/shirabe/src/console/application.rs +++ b/crates/shirabe/src/console/application.rs @@ -2596,13 +2596,15 @@ impl ApplicationHandle { // override TransportException's code for the purpose of parent::run() using it as process exit code // as http error codes are all beyond the 255 range of permitted exit codes - if e.downcast_ref::().is_some() { - // PHP: ReflectionProperty $reflProp = new \ReflectionProperty($e, 'code'); - // $reflProp->setValue($e, Installer::ERROR_TRANSPORT_EXCEPTION); - // TODO(phase-c): reflection-based mutation of the existing exception is not portable; - // we surface the rewritten code via a fresh TransportException at the call site. - let _ = Installer::ERROR_TRANSPORT_EXCEPTION; - } + // TODO(phase-c): PHP's `instanceof TransportException` also matches the subclass + // MaxFileSizeExceededException, which is a newtype here and is not matched by this downcast. + let e = match e.downcast::() { + Ok(mut e) => { + e.code = Installer::ERROR_TRANSPORT_EXCEPTION; + anyhow::Error::new(e) + } + Err(e) => e, + }; Err(e) } -- cgit v1.3.1