aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/util/auth_helper.rs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-06-05 01:50:16 +0900
committernsfisis <nsfisis@gmail.com>2026-06-05 01:50:16 +0900
commitbbb2f9454b6580fcbd337ced61b5a1888d52ce8d (patch)
tree45563449df57f63ae4a4d010a3e8e6007518c35b /crates/shirabe/src/util/auth_helper.rs
parentadf14510b00929aaee85ccb8dedf9164878a0164 (diff)
downloadphp-shirabe-bbb2f9454b6580fcbd337ced61b5a1888d52ce8d.tar.gz
php-shirabe-bbb2f9454b6580fcbd337ced61b5a1888d52ce8d.tar.zst
php-shirabe-bbb2f9454b6580fcbd337ced61b5a1888d52ce8d.zip
refactor(io): model ask_and_validate validators with anyhow::Result
PHP's askAndValidate throws when a validator rejects input. Change the IOInterface validator callback and return type to anyhow::Result so the call sites can return Err instead of panic, faithfully modeling the throw semantics already supported by the Question layer. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/util/auth_helper.rs')
-rw-r--r--crates/shirabe/src/util/auth_helper.rs20
1 files changed, 11 insertions, 9 deletions
diff --git a/crates/shirabe/src/util/auth_helper.rs b/crates/shirabe/src/util/auth_helper.rs
index 3471a54..0465b10 100644
--- a/crates/shirabe/src/util/auth_helper.rs
+++ b/crates/shirabe/src/util/auth_helper.rs
@@ -5,9 +5,9 @@ use anyhow::Result;
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::Preg;
use shirabe_php_shim::{
- E_USER_DEPRECATED, PHP_URL_HOST, PHP_URL_PATH, PHP_URL_SCHEME, PhpMixed, base64_encode,
- explode, in_array, is_array, is_string, json_decode, parse_url, sprintf, str_replace, strpos,
- strtolower, substr, trigger_error, trim,
+ E_USER_DEPRECATED, PHP_URL_HOST, PHP_URL_PATH, PHP_URL_SCHEME, PhpMixed, RuntimeException,
+ base64_encode, explode, in_array, is_array, is_string, json_decode, parse_url, sprintf,
+ str_replace, strpos, strtolower, substr, trigger_error, trim,
};
use crate::config::Config;
@@ -69,7 +69,7 @@ impl AuthHelper {
origin,
config_source.get_name(),
),
- Box::new(|value: PhpMixed| -> PhpMixed {
+ Box::new(|value: PhpMixed| -> anyhow::Result<PhpMixed> {
let input = strtolower(&substr(
&trim(value.as_string().unwrap_or(""), None),
0,
@@ -83,15 +83,17 @@ impl AuthHelper {
]),
false,
) {
- return PhpMixed::String(input);
+ return Ok(PhpMixed::String(input));
}
- // PHP: throw new \RuntimeException('Please answer (y)es or (n)o');
- // TODO(phase-b): validator should return a recoverable error rather than panic
- panic!("Please answer (y)es or (n)o");
+ Err(RuntimeException {
+ message: "Please answer (y)es or (n)o".to_string(),
+ code: 0,
+ }
+ .into())
}),
None,
PhpMixed::String("y".to_string()),
- );
+ )?;
if answer.as_string() == Some("y") {
store = Some(());