diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-06-06 19:09:49 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-06-06 19:09:49 +0900 |
| commit | c688de488d72e67ab1650b50adef4ad11f5de756 (patch) | |
| tree | b522ef7c82abbe8f1318fa693cc98fdb6815db6c /crates/shirabe/src/repository | |
| parent | 23f8a0dc3e08949ec78e050b7642c605fa2aaaf5 (diff) | |
| download | php-shirabe-c688de488d72e67ab1650b50adef4ad11f5de756.tar.gz php-shirabe-c688de488d72e67ab1650b50adef4ad11f5de756.tar.zst php-shirabe-c688de488d72e67ab1650b50adef4ad11f5de756.zip | |
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) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/repository')
| -rw-r--r-- | crates/shirabe/src/repository/installed_repository.rs | 30 |
1 files changed, 10 insertions, 20 deletions
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::<LockArrayRepository>() - || repository.is::<RootPackageRepository>() - || repository.is::<PlatformRepository>() - { - self.inner.add_repository(repository); - return Ok(()); - } + pub fn add_repository(&mut self, repository: RepositoryInterfaceHandle) { + // TODO: type guard? + assert!( + repository.is::<LockArrayRepository>() + || repository.is::<RootPackageRepository>() + || repository.is::<PlatformRepository>(), + "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); } } |
