diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-07-11 17:53:03 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-07-11 17:53:03 +0900 |
| commit | 4e1170c2328dd8007a5d737a759cd18030b1200b (patch) | |
| tree | a465e7dd04d57ad72758a929450e155606de8582 /crates/shirabe/src/console | |
| parent | b017a2bdeb52bb7ff154826468d25d9a49a87634 (diff) | |
| download | php-shirabe-4e1170c2328dd8007a5d737a759cd18030b1200b.tar.gz php-shirabe-4e1170c2328dd8007a5d737a759cd18030b1200b.tar.zst php-shirabe-4e1170c2328dd8007a5d737a759cd18030b1200b.zip | |
fix(console-application): render exceptions to ConsoleOutput's error output
Resolve the base_run render_exception TODO by downcasting the
OutputInterface handle to the concrete ConsoleOutput type, mirroring
`$output instanceof ConsoleOutputInterface` from Symfony's
Application::run.
Diffstat (limited to 'crates/shirabe/src/console')
| -rw-r--r-- | crates/shirabe/src/console/application.rs | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/crates/shirabe/src/console/application.rs b/crates/shirabe/src/console/application.rs index ec6988e2..55854f11 100644 --- a/crates/shirabe/src/console/application.rs +++ b/crates/shirabe/src/console/application.rs @@ -83,6 +83,7 @@ use shirabe_external_packages::symfony::console::input::InputOption; use shirabe_external_packages::symfony::console::input::argv_input::ArgvInput; use shirabe_external_packages::symfony::console::input::array_input::ArrayInput; use shirabe_external_packages::symfony::console::input::input_argument::InputArgument; +use shirabe_external_packages::symfony::console::output::ConsoleOutputInterface; use shirabe_external_packages::symfony::console::output::console_output::ConsoleOutput; use shirabe_external_packages::symfony::console::output::output_interface::{ self, OutputInterface, @@ -2610,9 +2611,16 @@ impl ApplicationHandle { e: &anyhow::Error, output: &std::rc::Rc<std::cell::RefCell<dyn OutputInterface>>| { // if ($output instanceof ConsoleOutputInterface) render to its error output - // TODO(review): downcasting a `dyn OutputInterface` to `ConsoleOutputInterface` - // is not directly expressible; the ConsoleOutputInterface branch needs design. - this.render_throwable(e, output.clone()); + // ConsoleOutput is the only OutputInterface implementor that also implements + // ConsoleOutputInterface, so `instanceof ConsoleOutputInterface` reduces to this + // downcast to the concrete type. + let error_output = shirabe_php_shim::AsAny::as_any(&*output.borrow()) + .downcast_ref::<ConsoleOutput>() + .map(|console_output| console_output.get_error_output()); + match error_output { + Some(error_output) => this.render_throwable(e, error_output), + None => this.render_throwable(e, output.clone()), + } }; let result = (|| -> anyhow::Result<i32> { |
