siyuan-note/siyuan · error

invalid bazaar downloads: %s

Error message

invalid bazaar downloads: %s

What it means

In the legacy index section each repo key maps to a stats object whose 'downloads' count must be non-negative. parseBazaarIndex throws this when a stats object unmarshals with a negative Downloads value.

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 8641553a1f)

Solutions

  1. Re-fetch the index from the official bazaar stat server; a negative count indicates bad upstream/cache data
  2. If you operate a mirror, clamp or fix the aggregation so downloads counters never go negative
  3. Locate the repo named in the error and correct its 'downloads' field to a non-negative integer

Example fix

// before
{"siyuan-note/foo": {"downloads": -12}}
// after
{"siyuan-note/foo": {"downloads": 0}}
Defensive patterns

Strategy: validation

Validate before calling

for repo, stats := range legacyStats {
	if stats.Downloads < 0 {
		return fmt.Errorf("negative downloads for %s", repo)
	}
}

Try / catch

snapshot, err := parseBazaarIndex(data)
if err != nil {
	if strings.HasPrefix(err.Error(), "invalid bazaar downloads:") {
		log.Errorf("corrupt download counters; refetch index")
	}
	return err
}

Prevention

When it happens

Trigger: An index JSON contains e.g. {"owner/repo": {"downloads": -3}}; after json.Unmarshal into bazaarStats, stats.Downloads < 0 triggers the error naming the offending raw repo key.

Common situations: Upstream stat server bug or manual edit producing negative counters; a mirror aggregating deltas incorrectly; corrupted cached JSON.

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@8641553a1f (2026-09-11). Data as JSON: /api/errors/18a741d7a2995908. Report an issue: GitHub.