aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/console/application.rs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-06 04:01:58 +0900
committernsfisis <nsfisis@gmail.com>2026-08-06 04:01:58 +0900
commitce6192f1cfaac63457b173f573ada661a4665bfb (patch)
treeef8fb5869fa88846f610e267423a7223e5d6903a /crates/shirabe/src/console/application.rs
parent9a6881276a6aeb4d3b49046045f6e26303cc6e52 (diff)
downloadphp-shirabe-ce6192f1cfaac63457b173f573ada661a4665bfb.tar.gz
php-shirabe-ce6192f1cfaac63457b173f573ada661a4665bfb.tar.zst
php-shirabe-ce6192f1cfaac63457b173f573ada661a4665bfb.zip
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) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/console/application.rs')
-rw-r--r--crates/shirabe/src/console/application.rs16
1 files changed, 9 insertions, 7 deletions
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::<TransportException>().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::<TransportException>() {
+ Ok(mut e) => {
+ e.code = Installer::ERROR_TRANSPORT_EXCEPTION;
+ anyhow::Error::new(e)
+ }
+ Err(e) => e,
+ };
Err(e)
}