aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/repository/array_repository.rs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-06-10 00:54:22 +0900
committernsfisis <nsfisis@gmail.com>2026-06-10 00:54:58 +0900
commite583112899cbea7494ffdd73d7de380dd5f808c4 (patch)
tree1ec002a4d9ab5af5f81ff3bc0ae0ea6a92e44c10 /crates/shirabe/src/repository/array_repository.rs
parent436e12381dd79e419dce755718be17b66d73e17f (diff)
downloadphp-shirabe-e583112899cbea7494ffdd73d7de380dd5f808c4.tar.gz
php-shirabe-e583112899cbea7494ffdd73d7de380dd5f808c4.tar.zst
php-shirabe-e583112899cbea7494ffdd73d7de380dd5f808c4.zip
feat(phase-c): resolve exception-handling phase-b TODOs
* Catch specific exception types instead of broad/placeholder handling. * Drop the shim Countable trait.
Diffstat (limited to 'crates/shirabe/src/repository/array_repository.rs')
-rw-r--r--crates/shirabe/src/repository/array_repository.rs34
1 files changed, 11 insertions, 23 deletions
diff --git a/crates/shirabe/src/repository/array_repository.rs b/crates/shirabe/src/repository/array_repository.rs
index 1eeb428..df25235 100644
--- a/crates/shirabe/src/repository/array_repository.rs
+++ b/crates/shirabe/src/repository/array_repository.rs
@@ -7,7 +7,7 @@ use std::rc::Weak;
use anyhow::Result;
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::Preg;
-use shirabe_php_shim::{Countable, LogicException, implode, preg_quote, strtolower};
+use shirabe_php_shim::{implode, preg_quote, strtolower};
use shirabe_semver::constraint::AnyConstraint;
use shirabe_semver::constraint::SimpleConstraint;
@@ -39,19 +39,10 @@ impl ArrayRepository {
if self.packages.borrow().is_none() {
self.initialize();
}
-
- if self.packages.borrow().is_none() {
- // TODO(phase-b): propagate the error.
- // PHP: throw new \LogicException('initialize failed to initialize the packages array')
- panic!(
- "{}",
- LogicException {
- message: "initialize failed to initialize the packages array".to_string(),
- code: 0,
- }
- .message
- );
- }
+ assert!(
+ self.packages.borrow().is_some(),
+ "initialize failed to initialize the packages array"
+ );
self.packages
.borrow()
@@ -155,25 +146,22 @@ impl ArrayRepository {
}
}
-impl Countable for ArrayRepository {
+impl RepositoryInterface for ArrayRepository {
/// Returns the number of packages in this repository
- ///
- /// @return 0|positive-int Number of packages
- fn count(&self) -> i64 {
+ fn count(&self) -> anyhow::Result<usize> {
if self.packages.borrow().is_none() {
self.initialize();
}
- self.packages.borrow().as_ref().unwrap().len() as i64
+ Ok(self.packages.borrow().as_ref().unwrap().len())
}
-}
-impl RepositoryInterface for ArrayRepository {
fn get_repo_name(&self) -> String {
+ let count = self.count().expect("ArrayRepository::count is infallible");
format!(
"array repo (defining {} package{})",
- self.count(),
- if self.count() > 1 { "s" } else { "" },
+ count,
+ if count > 1 { "s" } else { "" },
)
}