From 5e01c04ff01480f48bb332652920ec1254251ee0 Mon Sep 17 00:00:00 2001 From: abhinavgautam01 Date: Fri, 16 Oct 2026 11:21:06 +0530 Subject: [PATCH] Name the missing import in the unknown ecosystem error --- internal/core/registry.go | 4 +++- internal/core/registry_test.go | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 internal/core/registry_test.go diff --git a/internal/core/registry.go b/internal/core/registry.go index 77bf229..98871da 100644 --- a/internal/core/registry.go +++ b/internal/core/registry.go @@ -52,10 +52,12 @@ func New(ecosystem string, baseURL string, client *Client) (Registry, error) { / mu.RLock() factory, ok := factories[ecosystem] defaultURL := defaults[ecosystem] + registered := len(factories) mu.RUnlock() if !ok { - return nil, fmt.Errorf("unknown ecosystem: %s", ecosystem) + return nil, fmt.Errorf("unknown ecosystem %q (%d registered; import _ %q or the specific ecosystem package)", + ecosystem, registered, "github.com/git-pkgs/registries/all") } if baseURL == "" { diff --git a/internal/core/registry_test.go b/internal/core/registry_test.go new file mode 100644 index 0000000..57e6064 --- /dev/null +++ b/internal/core/registry_test.go @@ -0,0 +1,24 @@ +package core + +import ( + "strings" + "testing" +) + +func TestNewUnknownEcosystemErrorNamesFix(t *testing.T) { + _, err := New("no-such-ecosystem", "", nil) + if err == nil { + t.Fatal("expected error for unknown ecosystem") + } + + msg := err.Error() + for _, want := range []string{ + `unknown ecosystem "no-such-ecosystem"`, + "0 registered", + `import _ "github.com/git-pkgs/registries/all"`, + } { + if !strings.Contains(msg, want) { + t.Errorf("error %q does not contain %q", msg, want) + } + } +}