diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-08-08 22:14:12 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-08-08 22:14:12 +0900 |
| commit | f4cad2123b2af0de72bda4ce039e16e74f163f4e (patch) | |
| tree | 21803308c5ff41e23c9d3b117433eea16b4ff663 /crates/shirabe/src/util/bitbucket.rs | |
| parent | 0209f63210e5b547b5c6b73367bb80ea86c255ec (diff) | |
| download | php-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/util/bitbucket.rs')
| -rw-r--r-- | crates/shirabe/src/util/bitbucket.rs | 49 |
1 files changed, 19 insertions, 30 deletions
diff --git a/crates/shirabe/src/util/bitbucket.rs b/crates/shirabe/src/util/bitbucket.rs index 50d4b700..d8e245a9 100644 --- a/crates/shirabe/src/util/bitbucket.rs +++ b/crates/shirabe/src/util/bitbucket.rs @@ -9,10 +9,11 @@ use crate::io::io_interface; use crate::util::HttpDownloader; use crate::util::ProcessExecutor; use indexmap::IndexMap; +use shirabe_php_shim::Catch as _; use shirabe_php_shim::{LogicException, PhpMixed, time}; fn transport_error_code(err: &anyhow::Error) -> Option<i64> { - err.downcast_ref::<TransportException>().map(|te| te.code) + err.catch::<TransportException>().map(|te| te.get_code()) } #[derive(Debug)] @@ -167,24 +168,18 @@ impl Bitbucket { let token_map = match token { PhpMixed::Array(ref m) => m.clone(), _ => { - return Err(LogicException { - message: format!( - "Expected a token configured with expires_in and access_token present, got {}", - shirabe_php_shim::json_encode(&token).unwrap_or_default() - ), - code: 0, - } + return Err(LogicException::new(format!( + "Expected a token configured with expires_in and access_token present, got {}", + shirabe_php_shim::json_encode(&token).unwrap_or_default() + )) .into()); } }; if !token_map.contains_key("expires_in") || !token_map.contains_key("access_token") { - return Err(LogicException { - message: format!( - "Expected a token configured with expires_in and access_token present, got {}", - shirabe_php_shim::json_encode(&token).unwrap_or_default() - ), - code: 0, - } + return Err(LogicException::new(format!( + "Expected a token configured with expires_in and access_token present, got {}", + shirabe_php_shim::json_encode(&token).unwrap_or_default() + )) .into()); } self.token = Some(token_map.into_iter().collect()); @@ -350,11 +345,7 @@ impl Bitbucket { match access_token { Some(t) => Ok(t), - None => Err(LogicException { - message: "Failed to initialize token above".to_string(), - code: 0, - } - .into()), + None => Err(LogicException::new("Failed to initialize token above".to_string()).into()), } } @@ -370,9 +361,10 @@ impl Bitbucket { .get_config_source_mut() .remove_config_setting(&format!("bitbucket-oauth.{}", origin_url))?; - let token = self.token.as_ref().ok_or_else(|| LogicException { - message: "Expected a token configured with expires_in present, got null".to_string(), - code: 0, + let token = self.token.as_ref().ok_or_else(|| { + LogicException::new( + "Expected a token configured with expires_in present, got null".to_string(), + ) })?; let expires_in = token .get("expires_in") @@ -380,13 +372,10 @@ impl Bitbucket { .ok_or_else(|| { let token_mixed = PhpMixed::Array(token.iter().map(|(k, v)| (k.clone(), v.clone())).collect()); - LogicException { - message: format!( - "Expected a token configured with expires_in present, got {}", - shirabe_php_shim::json_encode(&token_mixed).unwrap_or_default() - ), - code: 0, - } + LogicException::new(format!( + "Expected a token configured with expires_in present, got {}", + shirabe_php_shim::json_encode(&token_mixed).unwrap_or_default() + )) })?; let t = self.time.unwrap_or_else(time); |
