siyuan-note/siyuan · error

invalid rating distribution returned by cloud server

Error message

invalid rating distribution returned by cloud server

What it means

Thrown by SetBazaarPackageRating when the distribution-only response path is taken (no ratingAvailable flag) and the cloud's Distribution array does not contain exactly 5 entries — one per star level (kernel/model/bazaar_rating.go:211-212). The client requires a full 5-element star distribution to update the local rating cache.

Solutions

  1. Verify the cloud endpoint returns a proper distribution array of exactly 5 integers for the package
  2. Update the SiYuan client to match the current cloud API response schema
  3. Check network middleboxes/proxies that might strip or alter response JSON
  4. Retry — if the server returned a transient error body shaped as success, a later request may succeed

Example fix

// before
if 5 != len(data.Distribution) {
    return nil, false, 0, errors.New("invalid rating distribution returned by cloud server")
}
// after: log the offending payload for diagnosis
if 5 != len(data.Distribution) {
    logging.LogWarnf("unexpected distribution length %d for %s", len(data.Distribution), packageName)
    return nil, false, 0, errors.New("invalid rating distribution returned by cloud server")
}
Defensive patterns

Strategy: validation

Validate before calling

if len(data.Distribution) != 5 { return errors.New("cloud distribution must contain exactly 5 star buckets") }

Try / catch

_, _, _, err := model.SetBazaarPackageRating(ctx, pkgType, name, userRating)
if err != nil && strings.Contains(err.Error(), "invalid rating distribution") {
    logging.LogWarnf("bad distribution payload for %s", name)
    return err
}

Prevention

When it happens

Trigger: SetBazaarPackageRating where the cloud response omits ratingAvailable and data.Distribution has length 0, 1-4, or more than 5 (e.g. null, empty array, or a schema change adding extra buckets).

Common situations: Cloud server API schema change; an error/empty body parsed into a zero-value Data struct because code/msg indicated success incorrectly; proxy stripping or truncating response fields; client pointed at a non-official cloud endpoint.

Understand the failure class

Background: "invalid response format", "malformed payload", "missing data field": when an API returns 200 but the response shape is wrong — this error's family across 23 libraries.

Related errors


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

Appendix: source

Thrown at kernel/model/bazaar_rating.go:212

				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 9f775e8a12)