Skip to content

Name the fix in the unknown ecosystem error - #101

Open
abhinavgautam01 wants to merge 1 commit into
git-pkgs:mainfrom
abhinavgautam01:fix/unknown-ecosystem-error-hint
Open

abhinavgautam01 wants to merge 1 commit into
git-pkgs:mainfrom
abhinavgautam01:fix/unknown-ecosystem-error-hint

Conversation

@abhinavgautam01

Copy link
Copy Markdown

Fixes #53

Problem

Each ecosystem registers itself from an init() function. If a program imports github.com/git-pkgs/registries without github.com/git-pkgs/registries/all (or the specific ecosystem package), no ecosystems get registered. Then calls like FetchPackageFromPURL(ctx, "pkg:pypi/flask", c) fail with:

unknown ecosystem: pypi

That message reads as if pypi is unsupported, when really an import is missing. It's even more confusing when some other dependency happens to register one ecosystem (say npm) but not the rest, because the failure then looks specific to one ecosystem.

Change

When an ecosystem isn't found, core.New now reports how many ecosystems are registered and names the import that registers them:

unknown ecosystem "pypi" (0 registered; import _ "github.com/git-pkgs/registries/all" or the specific ecosystem package)

The count separates the two cases: 0 registered means nothing was imported, while a nonzero count means the ecosystem really isn't available. It's read under the same read lock as the factory lookup, so the two values stay consistent.

registries.New, FetchPackageFromPURL and the other PURL helpers all go through core.New, so every one of them gets the new message.

Tests

  • Added internal/core/registry_test.go, which checks that the error includes the quoted ecosystem name, the registered count and the import hint.
  • go test -race ./..., go vet ./... and golangci-lint run ./... pass locally.
  • The GOOS=js and GOOS=wasip1 wasm builds pass, as do the tinygo-tagged tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Name the fix in the "unknown ecosystem" error

1 participant