From c688de488d72e67ab1650b50adef4ad11f5de756 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 6 Jun 2026 19:09:49 +0900 Subject: refactor(installed-repository): make add_repository infallible with assert The repository type check was an internal invariant, not a recoverable error condition. Replace the Result-returning validation with an assert!, matching Composer's design where add_repository throws only on a programming error, and drop the now-unneeded error handling at call sites. Co-Authored-By: Claude Opus 4.8 (1M context) --- .../shirabe/src/repository/installed_repository.rs | 30 ++++++++-------------- 1 file changed, 10 insertions(+), 20 deletions(-) (limited to 'crates/shirabe/src/repository') diff --git a/crates/shirabe/src/repository/installed_repository.rs b/crates/shirabe/src/repository/installed_repository.rs index b8321d6..2bd6fc6 100644 --- a/crates/shirabe/src/repository/installed_repository.rs +++ b/crates/shirabe/src/repository/installed_repository.rs @@ -43,9 +43,7 @@ impl InstalledRepository { inner: CompositeRepository::new(vec![]), }; for repo in repositories { - // TODO(phase-b): add_repository validates the inner repo type and may return Err; - // ignoring the error during Phase B since callers do not handle it. - let _ = this.add_repository(repo); + this.add_repository(repo); } this } @@ -366,24 +364,16 @@ impl InstalledRepository { Ok(results) } - pub fn add_repository(&mut self, repository: RepositoryInterfaceHandle) -> anyhow::Result<()> { - if repository.is::() - || repository.is::() - || repository.is::() - { - self.inner.add_repository(repository); - return Ok(()); - } + pub fn add_repository(&mut self, repository: RepositoryInterfaceHandle) { + // TODO: type guard? + assert!( + repository.is::() + || repository.is::() + || repository.is::(), + "An InstalledRepository can contain a repository of type: LockArrayRepository, RootPackageRepository or PlatformRepository" + ); - let type_name = std::any::type_name_of_val(&*repository.borrow()).to_string(); - let repo_name = repository.get_repo_name(); - Err(anyhow::anyhow!(LogicException { - message: format!( - "An InstalledRepository can not contain a repository of type {} ({})", - type_name, repo_name, - ), - code: 0, - })) + self.inner.add_repository(repository); } } -- cgit v1.3.1