From 2c3373a7466c31f5cce7c2867c00a91afaa8e128 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 2 Aug 2026 08:55:56 +0900 Subject: fix(io): propagate ask/select errors instead of panicking IOInterface::ask/select now return anyhow::Result, and ConsoleIO::ask_question forwards QuestionHelper errors (validator failures, MissingInputException) instead of collapsing them with .expect(). In PHP these exceptions propagate from QuestionHelper through ConsoleIO to the caller, so callers such as UpdateCommand's interactive package selection must be able to observe them; the MissingInputException is wrapped with its concrete type preserved so Application's ExceptionInterface downcast keeps working. All call sites now propagate with `?` (Perforce::query_p4_user becomes Result-returning: PHP declares it void but exceptions still escape), and the previously ignored test_interactive_mode_throws_if_no_package_entered passes. ask_confirmation/ask_and_hide_answer still collapse errors; extending propagation to them is left as TODO(phase-c) pending a decision. Co-Authored-By: Claude Fable 5 --- crates/shirabe/src/io/io_interface.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'crates/shirabe/src/io/io_interface.rs') diff --git a/crates/shirabe/src/io/io_interface.rs b/crates/shirabe/src/io/io_interface.rs index 33a2f017..b0271767 100644 --- a/crates/shirabe/src/io/io_interface.rs +++ b/crates/shirabe/src/io/io_interface.rs @@ -92,7 +92,10 @@ pub trait IOInterfaceImmutable: std::fmt::Debug { } fn overwrite_error4(&self, message: &str, newline: bool, size: Option, verbosity: i64); - fn ask(&self, question: String, default: PhpMixed) -> PhpMixed; + /// PHP: `@throws \RuntimeException If there is no data to read in the input stream`. + /// `QuestionHelper::ask` exceptions (validator errors, `MissingInputException`) propagate + /// to the caller, hence the `anyhow::Result` return type. + fn ask(&self, question: String, default: PhpMixed) -> anyhow::Result; fn ask_confirmation(&self, question: String, default: bool) -> bool; @@ -109,6 +112,10 @@ pub trait IOInterfaceImmutable: std::fmt::Debug { /// PHP `array $choices` may be a list (`PhpMixed::List`) or an associative /// array (`PhpMixed::Array`); list choices resolve to their index, while /// associative choices resolve to their key. + /// + /// PHP: `@throws \InvalidArgumentException` — the `ChoiceQuestion` validator error + /// propagates to the caller once `$attempts` is exhausted, hence the `anyhow::Result` + /// return type. fn select( &self, question: String, @@ -117,7 +124,7 @@ pub trait IOInterfaceImmutable: std::fmt::Debug { attempts: PhpMixed, error_message: String, multiselect: bool, - ) -> PhpMixed; + ) -> anyhow::Result; fn get_authentications(&self) -> IndexMap>>; @@ -278,7 +285,7 @@ impl IOInterfaceImmutable for std::rc::Rc> { .overwrite_error4(message, newline, size, verbosity) } - fn ask(&self, question: String, default: PhpMixed) -> PhpMixed { + fn ask(&self, question: String, default: PhpMixed) -> anyhow::Result { self.borrow().ask(question, default) } @@ -309,7 +316,7 @@ impl IOInterfaceImmutable for std::rc::Rc> { attempts: PhpMixed, error_message: String, multiselect: bool, - ) -> PhpMixed { + ) -> anyhow::Result { self.borrow().select( question, choices, -- cgit v1.3.1