siyuan-note/siyuan · error

invalid rating distribution for package: %s

Error message

invalid rating distribution for package: %s

What it means

After the length check, parseBazaarRatingRegion runs validBazaarRatingDistribution on the 5-element distribution (e.g. all values must be non-negative or otherwise consistent). A distribution with the right shape but invalid contents fails with this error naming the package.

Source

Thrown at kernel/bazaar/rating.go:446

	raw := map[string]json.RawMessage{}
	if err = json.Unmarshal(data, &raw); nil != err {
		return nil, err
	}
	ret = make(map[string]bazaarRatingDistribution, len(raw))
	for packageName, rawDistribution := range raw {
		if !IsValidPackageName(packageName) {
			return nil, fmt.Errorf("invalid package name: %s", packageName)
		}
		var values []int64
		if err = json.Unmarshal(rawDistribution, &values); nil != err {
			return nil, err
		}
		if 5 != len(values) {
			return nil, fmt.Errorf("invalid rating distribution length for package: %s", packageName)
		}
		distribution := bazaarRatingDistribution(values)
		if !validBazaarRatingDistribution(distribution) {
			return nil, fmt.Errorf("invalid rating distribution for package: %s", packageName)
		}
		ret[packageName] = distribution
	}
	return
}

func mergeBazaarRatingRegions(regions [bazaarRatingRegionCount]bazaarRatingRegionResult) map[string]*PackageRating {
	distributions := map[string]bazaarRatingDistribution{}
	for _, region := range regions {
		for packageName, distribution := range region.data {
			merged := distributions[packageName]
			valid := true
			for i, count := range distribution {
				if count > math.MaxInt64-merged[i] {
					valid = false
					break
				}
				merged[i] += count

View on GitHub (pinned to 8641553a1f)

Solutions

  1. Read validBazaarRatingDistribution to learn the exact invariants, then check the named package's values against them
  2. Correct negative or invalid counts in the source JSON/fixture
  3. Re-fetch the rating payload in case of data corruption in transit
  4. Report upstream if the marketplace itself serves invalid distributions

Example fix

// before
"pkg": [-1, 2, 0, 0, 0]
// after
"pkg": [1, 2, 0, 0, 0] // all buckets validator-consistent
Defensive patterns

Strategy: validation

Validate before calling

func validDist(values []int64) bool {
    if len(values) != 5 { return false }
    for _, v := range values { if v < 0 { return false } }
    return true // extend to match validBazaarRatingDistribution invariants
}

Try / catch

dist, err := parseBazaarRatingRegion(data)
if err != nil && strings.Contains(err.Error(), "invalid rating distribution for package") {
    // quarantine payload, log package name, fall back to cached ratings
}

Prevention

When it happens

Trigger: Calling parseBazaarRatingRegion / fetchBazaarRatingRegion on JSON where a package's 5-element distribution contains values violating validBazaarRatingDistribution's invariants — typically a negative count or otherwise inconsistent totals.

Common situations: Corrupted or tampered rating index; a test fixture using sentinel values like [-1,0,0,0,0]; an upstream data bug producing negative or nonsensical counts.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@8641553a1f (2026-09-11). Data as JSON: /api/errors/e99e749713b881ce. Report an issue: GitHub.