aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/config.rs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-08 22:14:12 +0900
committernsfisis <nsfisis@gmail.com>2026-08-08 22:14:12 +0900
commitf4cad2123b2af0de72bda4ce039e16e74f163f4e (patch)
tree21803308c5ff41e23c9d3b117433eea16b4ff663 /crates/shirabe/src/config.rs
parent0209f63210e5b547b5c6b73367bb80ea86c255ec (diff)
downloadphp-shirabe-f4cad2123b2af0de72bda4ce039e16e74f163f4e.tar.gz
php-shirabe-f4cad2123b2af0de72bda4ce039e16e74f163f4e.tar.zst
php-shirabe-f4cad2123b2af0de72bda4ce039e16e74f163f4e.zip
feat(php-shim): give ported exceptions PHP's class hierarchy
Ported exceptions were flat structs reached with `downcast_ref`, so Composer's `catch (\RuntimeException $e)` only matched the exact leaf type and `get_class($e)` had nothing to report. Each exception now embeds an instance of the class it extends and travels inside an `AnyThrowable`; `Catch::catch`/`catch_mut` walk that chain, and `PhpClass::php_class_name` yields the PHP FQCN. Dropping the `std::error::Error` impls from the exception types leaves `AnyThrowable` as the only route into an `anyhow::Error`, so the walk cannot be bypassed. A `no_exception_downcast` linter catches the `downcast::<X>()` calls that would now silently answer `None`. Three sites change behavior as a result: the `TransportException` exit-code override reaches `MaxFileSizeExceededException`, the `catch (\LogicException)` in findSimilar() reaches its subclasses, and rendered exception titles carry the real class name rather than a guess. `get_class_err()` is no longer a `todo!()`, which re-enables FilesystemRepositoryTest::testCorruptedRepositoryFile. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/config.rs')
-rw-r--r--crates/shirabe/src/config.rs70
1 files changed, 26 insertions, 44 deletions
diff --git a/crates/shirabe/src/config.rs b/crates/shirabe/src/config.rs
index 154fbd05..300b9bfa 100644
--- a/crates/shirabe/src/config.rs
+++ b/crates/shirabe/src/config.rs
@@ -658,10 +658,10 @@ impl Config {
&raw,
Some(&mut matches),
) {
- return Err(RuntimeException {
- message: format!("Could not parse the value of '{}': {}", key, raw),
- code: 0,
- }
+ return Err(RuntimeException::new(format!(
+ "Could not parse the value of '{}': {}",
+ key, raw
+ ))
.into());
}
let mut size = matches
@@ -735,13 +735,10 @@ impl Config {
PhpMixed::String("symlink".to_string()),
],
) {
- return Err(RuntimeException {
- message: format!(
- "Invalid value for 'bin-compat': {}. Expected auto, full or proxy",
- value
- ),
- code: 0,
- }
+ return Err(RuntimeException::new(format!(
+ "Invalid value for 'bin-compat': {}. Expected auto, full or proxy",
+ value
+ ))
.into());
}
@@ -760,13 +757,10 @@ impl Config {
if !matches!(env, PhpMixed::Bool(false)) {
let env_str = env.as_string().unwrap_or("").to_string();
if !matches!(env_str.as_str(), "stash" | "true" | "false" | "1" | "0") {
- return Err(RuntimeException {
- message: format!(
- "Invalid value for COMPOSER_DISCARD_CHANGES: {}. Expected 1, 0, true, false or stash",
- env_str
- ),
- code: 0,
- }
+ return Err(RuntimeException::new(format!(
+ "Invalid value for COMPOSER_DISCARD_CHANGES: {}. Expected 1, 0, true, false or stash",
+ env_str
+ ))
.into());
}
if env_str == "stash" {
@@ -782,13 +776,10 @@ impl Config {
let val = self.config.get(key).cloned().unwrap_or(PhpMixed::Null);
let allowed = matches!(&val, PhpMixed::Bool(_)) || val.as_string() == Some("stash");
if !allowed {
- return Err(RuntimeException {
- message: format!(
- "Invalid value for 'discard-changes': {:?}. Expected true, false or stash",
- val
- ),
- code: 0,
- }
+ return Err(RuntimeException::new(format!(
+ "Invalid value for 'discard-changes': {:?}. Expected true, false or stash",
+ val
+ ))
.into());
}
@@ -824,10 +815,7 @@ impl Config {
}
let first = protos.first().cloned();
if first.as_deref() == Some("http") {
- return Err(RuntimeException {
- message: "The http protocol for github is not available anymore, update your config's github-protocols to use \"https\", \"git\" or \"ssh\"".to_string(),
- code: 0,
- }
+ return Err(RuntimeException::new("The http protocol for github is not available anymore, update your config's github-protocols to use \"https\", \"git\" or \"ssh\"".to_string())
.into());
}
@@ -860,14 +848,11 @@ impl Config {
.map(|s| PhpMixed::String(s.clone()))
.collect::<Vec<_>>(),
) {
- return Err(RuntimeException {
- message: format!(
- "Invalid value for COMPOSER_AUDIT_ABANDONED: {}. Expected one of {}.",
- abandoned_env_str,
- implode(", ", &valid_choices),
- ),
- code: 0,
- }
+ return Err(RuntimeException::new(format!(
+ "Invalid value for COMPOSER_AUDIT_ABANDONED: {}. Expected one of {}.",
+ abandoned_env_str,
+ implode(", ", &valid_choices),
+ ))
.into());
}
if let PhpMixed::Array(ref mut m) = result {
@@ -880,13 +865,10 @@ impl Config {
if !matches!(block_abandoned_env, PhpMixed::Bool(false)) {
let env_str = block_abandoned_env.as_string().unwrap_or("").to_string();
if !matches!(env_str.as_str(), "0" | "1") {
- return Err(RuntimeException {
- message: format!(
- "Invalid value for COMPOSER_SECURITY_BLOCKING_ABANDONED: {}. Expected 0 or 1.",
- env_str
- ),
- code: 0,
- }
+ return Err(RuntimeException::new(format!(
+ "Invalid value for COMPOSER_SECURITY_BLOCKING_ABANDONED: {}. Expected 0 or 1.",
+ env_str
+ ))
.into());
}
if let PhpMixed::Array(ref mut m) = result {