siyuan-note/siyuan · error

invalid bazaar downloads

Error message

invalid bazaar downloads: %s

What it means

After a legacy repository key normalizes, its stats JSON is unmarshalled and its Downloads must be >= 0; a negative value aborts parsing with the repository name in the message. Downloads counts are aggregated across aliases, and negative input would corrupt the running sum.

Solutions

  1. Fix the negative downloads value in the bazaar stats source
  2. Re-fetch the index after upstream stats are corrected
  3. Change the fixture to use a non-negative downloads value

Example fix

// before
{"siyuan-note/siyuan":{"downloads":-5}}
// after
{"siyuan-note/siyuan":{"downloads":5}}
Defensive patterns

Strategy: validation

Validate before calling

for (const [repo, stats] of Object.entries(idx)) {
  if (repo !== "meta" && repo !== "packages" && typeof stats.downloads === "number" && stats.downloads < 0) throw new Error(`negative downloads for ${repo}`)
}

Prevention

When it happens

Trigger: fetchBazaarIndexPath receives a legacy index where <repo> maps to an object whose downloads field is negative (e.g. {"downloads":-5}) or of a type unmarshalling to a negative number.

Common situations: An upstream stats counter underflowed; a manual edit or data-migration script wrote negative counts; a fixture built with placeholder negative numbers.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/18a741d7a2995908. Report an issue: GitHub.

Appendix: source

Thrown at kernel/bazaar/index.go:264

	} else if hasPackages {
		return nil, errors.New("incomplete bazaar index metadata")
	}

	if !hasMeta || 2 == ret.meta.Schema || bazaarIndexSchema < ret.meta.Schema {
		for rawRepo, rawStats := range raw {
			if "meta" == rawRepo || "packages" == rawRepo {
				continue
			}
			repo, valid := normalizeLegacyBazaarRepo(rawRepo)
			if !valid {
				return nil, fmt.Errorf("invalid bazaar repository: %s", rawRepo)
			}
			stats := &bazaarStats{}
			if err = json.Unmarshal(rawStats, stats); nil != err {
				return nil, err
			}
			if 0 > stats.Downloads {
				return nil, fmt.Errorf("invalid bazaar downloads: %s", rawRepo)
			}
			if current := ret.legacyStats[repo]; nil != current {
				if stats.Downloads > int(^uint(0)>>1)-current.Downloads {
					return nil, fmt.Errorf("bazaar downloads overflow: %s", repo)
				}
				current.Downloads += stats.Downloads
				continue
			}
			ret.legacyStats[repo] = stats
		}
	}
	return
}

func normalizeLegacyBazaarRepo(repo string) (string, bool) {
	const githubPrefix = "https://github.com/"
	if strings.HasPrefix(repo, githubPrefix) {
		repo = strings.TrimPrefix(repo, githubPrefix)

View on GitHub (pinned to 9f775e8a12)