Skip to content

Commit 1e26aa2

Browse files
committed
internal/mod/modregistry: remove error return from New
There's no way that `modregistry.New` can fail, so remove the error, simplifying the calls. Signed-off-by: Roger Peppe <[email protected]> Change-Id: Ib305056b94bef2067006dd6d6bf74e296caaac4b Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1170881 TryBot-Result: CUEcueckoo <[email protected]> Reviewed-by: Daniel Martí <[email protected]> Unity-Result: CUE porcuepine <[email protected]>
1 parent 2a7d1d6 commit 1e26aa2

File tree

5 files changed

+6
-18
lines changed

5 files changed

+6
-18
lines changed

cue/load/registry.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,8 @@ type registryClient struct {
2929
// in the registry is immutable, so if it's in the cache, a module
3030
// will not be downloaded again.
3131
func newRegistryClient(registry ociregistry.Interface, cacheDir string) (*registryClient, error) {
32-
client, err := modregistry.NewClient(registry)
33-
if err != nil {
34-
return nil, err
35-
}
3632
return &registryClient{
37-
client: client,
33+
client: modregistry.NewClient(registry),
3834
cacheDir: cacheDir,
3935
}, nil
4036
}

internal/mod/modregistry/client.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ const (
5151

5252
// NewClient returns a new client that talks to the registry at the given
5353
// hostname.
54-
func NewClient(registry ociregistry.Interface) (*Client, error) {
54+
func NewClient(registry ociregistry.Interface) *Client {
5555
return &Client{
5656
registry: registry,
57-
}, nil
57+
}
5858
}
5959

6060
// GetModule returns the module instance for the given version.

internal/mod/modregistry/client_test.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ import (
3434
)
3535

3636
func newTestClient(t *testing.T) *Client {
37-
c, err := NewClient(ocimem.New())
38-
qt.Assert(t, qt.IsNil(err))
39-
return c
37+
return NewClient(ocimem.New())
4038
}
4139

4240
func TestPutGetModule(t *testing.T) {

internal/registrytest/registry.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,7 @@ import (
3636
// The Registry should be closed after use.
3737
func New(fsys fs.FS, prefix string) (*Registry, error) {
3838
r := ocimem.New()
39-
client, err := modregistry.NewClient(ocifilter.Sub(r, prefix))
40-
if err != nil {
41-
return nil, fmt.Errorf("cannot make client: %v", err)
42-
}
39+
client := modregistry.NewClient(ocifilter.Sub(r, prefix))
4340

4441
mods, err := getModules(fsys)
4542
if err != nil {

internal/registrytest/registry_test.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,7 @@ func TestRegistry(t *testing.T) {
5050

5151
func runTest(t *testing.T, registry ociregistry.Interface, script string, ar *txtar.Archive) {
5252
ctx := context.Background()
53-
client, err := modregistry.NewClient(registry)
54-
if err != nil {
55-
t.Fatal(err)
56-
}
53+
client := modregistry.NewClient(registry)
5754
for _, line := range strings.Split(script, "\n") {
5855
if line == "" || line[0] == '#' {
5956
continue

0 commit comments

Comments
 (0)