siyuan-note/siyuan · error

invalid rating distribution returned by cloud server

Error message

invalid rating distribution returned by cloud server

What it means

Outside the RatingAvailable branches, the kernel requires the server to return a full 5-bucket rating distribution and, when the user rating is nonzero, at least one vote at that star level (kernel/model/bazaar_rating.go:199-205). It then applies the distribution locally via ApplyBazaarPackageRatingDistribution, so an empty, wrong-length, or contradictory distribution — or a failed apply — invalidates the response.

Source

Thrown at kernel/model/bazaar_rating.go:200

				return nil, true, data.Rating, nil
			}
			if 0 < data.Rating && 1 > data.PublicRating.Distribution[data.Rating-1] {
				return nil, false, 0, errors.New("invalid public rating returned by cloud server")
			}
			if !bazaar.ApplyBazaarPackageRating(packageName, data.PublicRating) {
				return nil, false, 0, errors.New("invalid public rating returned by cloud server")
			}
			rating, ratingAvailable = bazaar.GetCachedBazaarPackageRating(packageName)
			if !ratingAvailable || nil == rating {
				return nil, false, 0, errors.New("invalid public rating returned by cloud server")
			}
			return rating, true, data.Rating, nil
		}
	} else if nil != data.PublicRating {
		return nil, false, 0, errors.New("invalid public rating returned by cloud server")
	}
	if 5 != len(data.Distribution) {
		return nil, false, 0, errors.New("invalid rating distribution returned by cloud server")
	}
	distribution := [5]int64(data.Distribution)
	if 0 < data.Rating && 1 > distribution[data.Rating-1] {
		return nil, false, 0, errors.New("invalid rating distribution returned by cloud server")
	}
	if !bazaar.ApplyBazaarPackageRatingDistribution(region, packageName, distribution) {
		return nil, false, 0, errors.New("invalid rating distribution returned by cloud server")
	}

	rating, ratingAvailable = bazaarRatingAfterUpdate(ctx, region, packageName, distribution)
	return rating, ratingAvailable, data.Rating, nil
}

func validateBazaarPackageRatingRequest0(ctx context.Context, pkgType, packageName string) (token string, err error) {
	if !isValidBazaarPackageType(pkgType) {
		return "", errors.New("invalid package type")
	}
	if !bazaar.IsValidPackageName(packageName) {

View on GitHub (pinned to 8641553a1f)

Solutions

  1. Retry after a short delay so the server aggregate includes the new vote and returns a full 5-element distribution
  2. Ensure the package is installed and present in the local bazaar cache so ApplyBazaarPackageRatingDistribution can persist
  3. Verify region configuration (util.CurrentCloudRegion) and use the official endpoint for that region
  4. Upgrade kernel/cloud components to matching versions; restart the kernel to rebuild caches if state is suspect
Defensive patterns

Strategy: retry

Validate before calling

len(dist) == 5 && (userRating == 0 || dist[userRating-1] >= 1)

Type guard

func validDistribution(dist []int64, userRating int) bool {
    return len(dist) == 5 && (userRating == 0 || dist[userRating-1] >= 1)
}

Try / catch

if err != nil && strings.Contains(err.Error(), "invalid rating distribution returned by cloud server") {
    // backoff-retry; ensure package installed and region endpoint correct
}

Prevention

When it happens

Trigger: data.Distribution has length != 5; or Distribution[data.Rating-1] < 1 for a nonzero rating; or ApplyBazaarPackageRatingDistribution(region, packageName, distribution) returns false — all raised from the legacy/no-flag response path of SetBazaarPackageRating.

Common situations: Old or third-party bazaar endpoints returning partial distributions, aggregate caches that lag behind a fresh vote, package not registered in the local rating store so the distribution cannot be applied, or test stubs returning truncated arrays.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


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