aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/util
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-02 08:55:56 +0900
committernsfisis <nsfisis@gmail.com>2026-08-02 08:55:56 +0900
commit2c3373a7466c31f5cce7c2867c00a91afaa8e128 (patch)
tree754c7da92def5d14fc425230f9db41c654897b4f /crates/shirabe/src/util
parent92f5c977b42d1322f3cebb260024179e1285b9d0 (diff)
downloadphp-shirabe-2c3373a7466c31f5cce7c2867c00a91afaa8e128.tar.gz
php-shirabe-2c3373a7466c31f5cce7c2867c00a91afaa8e128.tar.zst
php-shirabe-2c3373a7466c31f5cce7c2867c00a91afaa8e128.zip
fix(io): propagate ask/select errors instead of panicking
IOInterface::ask/select now return anyhow::Result<PhpMixed>, 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 <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/util')
-rw-r--r--crates/shirabe/src/util/auth_helper.rs6
-rw-r--r--crates/shirabe/src/util/forgejo.rs2
-rw-r--r--crates/shirabe/src/util/git.rs2
-rw-r--r--crates/shirabe/src/util/gitlab.rs2
-rw-r--r--crates/shirabe/src/util/perforce.rs12
-rw-r--r--crates/shirabe/src/util/svn.rs2
6 files changed, 15 insertions, 11 deletions
diff --git a/crates/shirabe/src/util/auth_helper.rs b/crates/shirabe/src/util/auth_helper.rs
index 0a2dbf86..8a621eb1 100644
--- a/crates/shirabe/src/util/auth_helper.rs
+++ b/crates/shirabe/src/util/auth_helper.rs
@@ -168,7 +168,7 @@ impl AuthHelper {
"After authorizing your token, confirm that you would like to retry the request"
.to_string(),
PhpMixed::Null,
- );
+ )?;
return Ok(PromptAuthResult {
retry: true,
@@ -420,7 +420,9 @@ impl AuthHelper {
true,
io_interface::NORMAL,
);
- let username = self.io.ask(" Username: ".to_string(), PhpMixed::Null);
+ let username = self
+ .io
+ .ask(" Username: ".to_string(), PhpMixed::Null)?;
let password = self.io.ask_and_hide_answer(" Password: ".to_string());
self.io.borrow_mut().set_authentication(
origin.to_string(),
diff --git a/crates/shirabe/src/util/forgejo.rs b/crates/shirabe/src/util/forgejo.rs
index 41d0dd3d..34d44b7b 100644
--- a/crates/shirabe/src/util/forgejo.rs
+++ b/crates/shirabe/src/util/forgejo.rs
@@ -80,7 +80,7 @@ impl Forgejo {
let username = self
.io
- .ask("Username: ".to_string(), shirabe_php_shim::PhpMixed::Null)
+ .ask("Username: ".to_string(), shirabe_php_shim::PhpMixed::Null)?
.as_string()
.map(|s| s.trim().to_string())
.unwrap_or_default();
diff --git a/crates/shirabe/src/util/git.rs b/crates/shirabe/src/util/git.rs
index 3e650fd1..1c3474ea 100644
--- a/crates/shirabe/src/util/git.rs
+++ b/crates/shirabe/src/util/git.rs
@@ -703,7 +703,7 @@ impl Git {
default_username
.map(PhpMixed::String)
.unwrap_or(PhpMixed::Null),
- )
+ )?
.as_string()
.map(|s| s.to_string()),
);
diff --git a/crates/shirabe/src/util/gitlab.rs b/crates/shirabe/src/util/gitlab.rs
index 485d4126..2b23cdbf 100644
--- a/crates/shirabe/src/util/gitlab.rs
+++ b/crates/shirabe/src/util/gitlab.rs
@@ -419,7 +419,7 @@ impl GitLab {
}
fn create_token(&mut self, scheme: &str, origin_url: &str) -> anyhow::Result<PhpMixed> {
- let username = match self.io.ask("Username: ".to_string(), PhpMixed::Null) {
+ let username = match self.io.ask("Username: ".to_string(), PhpMixed::Null)? {
PhpMixed::String(s) => s,
_ => String::new(),
};
diff --git a/crates/shirabe/src/util/perforce.rs b/crates/shirabe/src/util/perforce.rs
index 9cd804a4..e2591301 100644
--- a/crates/shirabe/src/util/perforce.rs
+++ b/crates/shirabe/src/util/perforce.rs
@@ -253,18 +253,18 @@ impl Perforce {
self.p4_user = user;
}
- pub fn query_p4_user(&mut self) {
+ pub fn query_p4_user(&mut self) -> anyhow::Result<()> {
let _ = self.get_user();
if strlen(&self.p4_user.clone().unwrap_or_default()) > 0 {
- return;
+ return Ok(());
}
self.p4_user = self.get_p4_variable("P4USER");
if strlen(&self.p4_user.clone().unwrap_or_default()) > 0 {
- return;
+ return Ok(());
}
self.p4_user = self
.io
- .ask("Enter P4 User:".to_string(), PhpMixed::Null)
+ .ask("Enter P4 User:".to_string(), PhpMixed::Null)?
.as_string()
.map(|s| s.to_string());
let command = if self.windows_flag {
@@ -280,6 +280,8 @@ impl Perforce {
)
};
self.execute_command(PhpMixed::String(command));
+
+ Ok(())
}
pub(crate) fn get_p4_variable(&mut self, name: &str) -> Option<String> {
@@ -554,7 +556,7 @@ impl Perforce {
}
pub fn p4_login(&mut self) -> anyhow::Result<()> {
- self.query_p4_user();
+ self.query_p4_user()?;
if !self.is_logged_in()? {
let password = self.query_p4_password();
if self.windows_flag {
diff --git a/crates/shirabe/src/util/svn.rs b/crates/shirabe/src/util/svn.rs
index 67501e5a..50315316 100644
--- a/crates/shirabe/src/util/svn.rs
+++ b/crates/shirabe/src/util/svn.rs
@@ -234,7 +234,7 @@ impl Svn {
self.credentials = Some(SvnCredentials {
username: self
.io
- .ask("Username: ".to_string(), PhpMixed::String("".to_string()))
+ .ask("Username: ".to_string(), PhpMixed::String("".to_string()))?
.as_string()
.unwrap_or("")
.to_string(),