siyuan-note/siyuan · error

invalid public rating returned by cloud server

Error message

invalid public rating returned by cloud server

What it means

Error returned by model.SetBazaarPackageRating (kernel/model/bazaar_rating.go:164 and surrounding branches) when the cloud's setBazaarPackageRating response is internally inconsistent. Several combinations trigger it: RatingAvailable=false but a PublicRating is present; RatingAvailable=true without PublicRating while the rating is non-zero or the local cache clear fails; a set rating whose distribution bucket is zero; or ApplyBazaarPackageRating/GetCachedBazaarPackageRating round-trip checks failing. It is the kernel defending the local rating cache against contradictory server payloads.

Source

Thrown at kernel/model/bazaar_rating.go:164

	}

	region := util.CurrentCloudRegion
	data := bazaarPackageSetRatingData{}
	err = requestBazaarPackageRating(ctx, "/apis/siyuan/bazaar/setBazaarPackageRating", map[string]any{
		"token":       token,
		"packageName": packageName,
		"rating":      userRating,
	}, &data)
	if nil != err {
		return nil, false, 0, err
	}
	if data.Rating != userRating {
		return nil, false, 0, errors.New("invalid user rating returned by cloud server")
	}
	if nil != data.RatingAvailable {
		if !*data.RatingAvailable {
			if nil != data.PublicRating {
				return nil, false, 0, errors.New("invalid public rating returned by cloud server")
			}
			if 0 == len(data.Distribution) {
				return nil, false, data.Rating, nil
			}
		} else {
			if nil == data.PublicRating {
				if 0 != data.Rating || !bazaar.ClearBazaarPackageRating(packageName) {
					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 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")
			}

View on GitHub (pinned to afa823b6b4)

Solutions

  1. Retry the rating submission after a short delay so the backend reaches a consistent state
  2. Update to the latest kernel version if the response schema changed
  3. If reproducible on the latest version, capture the cloud response (endpoint /apis/siyuan/bazaar/setBazaarPackageRating) and report upstream; no local data change is applied when this fires
Defensive patterns

Strategy: retry

Try / catch

_, _, _, err := model.SetBazaarPackageRating(ctx, pkgType, name, stars)
if err != nil && strings.Contains(err.Error(), "invalid public rating returned by cloud server") {
    // backend payload inconsistent: single delayed retry; on repeat, report upstream and keep cache untouched
}

Prevention

When it happens

Trigger: A successful set call whose payload mixes states, e.g. "ratings unavailable" yet carrying publicRating JSON, or "available" with a non-zero user rating but an empty/zero distribution; also when the local cache was concurrently mutated so the post-apply verification read fails.

Common situations: Backend transitional states while a package's ratings are being recomputed; partial outages producing franken-payloads; long-running clients holding a stale cache colliding with a fresh response; version skew between kernel validation logic and a changed backend contract.

Related errors


AI-assisted analysis of siyuan-note/siyuan@afa823b6b4 (2026-08-18). Data as JSON: /api/errors/26aa4d1d870775ca. Report an issue: GitHub.