Skip to content

Commit

Permalink
internal/mod/modregistry: remove error return from New
Browse files Browse the repository at this point in the history
There's no way that `modregistry.New` can fail, so remove the error,
simplifying the calls.

Signed-off-by: Roger Peppe <rogpeppe@gmail.com>
Change-Id: Ib305056b94bef2067006dd6d6bf74e296caaac4b
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1170881
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
  • Loading branch information
rogpeppe committed Oct 18, 2023
1 parent 2a7d1d6 commit 1e26aa2
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 18 deletions.
6 changes: 1 addition & 5 deletions cue/load/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,8 @@ type registryClient struct {
// in the registry is immutable, so if it's in the cache, a module
// will not be downloaded again.
func newRegistryClient(registry ociregistry.Interface, cacheDir string) (*registryClient, error) {
client, err := modregistry.NewClient(registry)
if err != nil {
return nil, err
}
return &registryClient{
client: client,
client: modregistry.NewClient(registry),
cacheDir: cacheDir,
}, nil
}
Expand Down
4 changes: 2 additions & 2 deletions internal/mod/modregistry/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ const (

// NewClient returns a new client that talks to the registry at the given
// hostname.
func NewClient(registry ociregistry.Interface) (*Client, error) {
func NewClient(registry ociregistry.Interface) *Client {
return &Client{
registry: registry,
}, nil
}
}

// GetModule returns the module instance for the given version.
Expand Down
4 changes: 1 addition & 3 deletions internal/mod/modregistry/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ import (
)

func newTestClient(t *testing.T) *Client {
c, err := NewClient(ocimem.New())
qt.Assert(t, qt.IsNil(err))
return c
return NewClient(ocimem.New())
}

func TestPutGetModule(t *testing.T) {
Expand Down
5 changes: 1 addition & 4 deletions internal/registrytest/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ import (
// The Registry should be closed after use.
func New(fsys fs.FS, prefix string) (*Registry, error) {
r := ocimem.New()
client, err := modregistry.NewClient(ocifilter.Sub(r, prefix))
if err != nil {
return nil, fmt.Errorf("cannot make client: %v", err)
}
client := modregistry.NewClient(ocifilter.Sub(r, prefix))

mods, err := getModules(fsys)
if err != nil {
Expand Down
5 changes: 1 addition & 4 deletions internal/registrytest/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@ func TestRegistry(t *testing.T) {

func runTest(t *testing.T, registry ociregistry.Interface, script string, ar *txtar.Archive) {
ctx := context.Background()
client, err := modregistry.NewClient(registry)
if err != nil {
t.Fatal(err)
}
client := modregistry.NewClient(registry)
for _, line := range strings.Split(script, "\n") {
if line == "" || line[0] == '#' {
continue
Expand Down

0 comments on commit 1e26aa2

Please sign in to comment.