Skip to content

Commit

Permalink
reporegistry: add NoReposLoadedError and use it
Browse files Browse the repository at this point in the history
Add `NoReposLoadedError` custom error type for the case when any
function that is supposed to load repository configs, does not load
any. Use it in all functions that are directly loading repositories
from configuration files.

I considered `NoReposError` name, but that could be later added for
functions such as `RepoRegistry.ReposBy...()`, in case there are no
repositories in the RepoRegistry for the given image type / arch.

Signed-off-by: Tomáš Hozza <[email protected]>
  • Loading branch information
thozza authored and mvo5 committed Oct 25, 2024
1 parent 1ba13ea commit a30708c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
13 changes: 13 additions & 0 deletions pkg/reporegistry/error.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package reporegistry

import "fmt"

// NoReposLoadedError is an error type that is returned when no repositories
// are loaded from the given paths.
type NoReposLoadedError struct {
Paths []string
}

func (e *NoReposLoadedError) Error() string {
return fmt.Sprintf("no repositories found in the given paths: %v", e.Paths)
}
3 changes: 0 additions & 3 deletions pkg/reporegistry/reporegistry.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ func New(repoConfigPaths []string) (*RepoRegistry, error) {
if err != nil {
return nil, err
}
if len(repositories) == 0 {
return nil, fmt.Errorf("no repositories found in the given paths: %v", repoConfigPaths)
}

return &RepoRegistry{repositories}, nil
}
Expand Down
7 changes: 5 additions & 2 deletions pkg/reporegistry/repository.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package reporegistry

import (
"fmt"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -66,6 +65,10 @@ func LoadAllRepositories(confPaths []string) (rpmmd.DistrosRepoConfigs, error) {
}
}

if len(distrosRepoConfigs) == 0 {
return nil, &NoReposLoadedError{confPaths}
}

return distrosRepoConfigs, nil
}

Expand Down Expand Up @@ -93,7 +96,7 @@ func LoadRepositories(confPaths []string, distro string) (map[string][]rpmmd.Rep
}

if repoConfigs == nil {
return nil, fmt.Errorf("LoadRepositories failed: none of the provided paths contain distro configuration")
return nil, &NoReposLoadedError{confPaths}
}

return repoConfigs, nil
Expand Down

0 comments on commit a30708c

Please sign in to comment.