{"record":{"id":"09797dcc9b145f61","repo":"siyuan-note/siyuan","slug":"invalid-rating-distribution-returned-by-cloud-serv","errorCode":null,"errorMessage":"invalid rating distribution returned by cloud server","messagePattern":"invalid rating distribution returned by cloud server","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/bazaar_rating.go","lineNumber":200,"sourceCode":"\t\t\t\treturn nil, true, data.Rating, nil\n\t\t\t}\n\t\t\tif 0 < data.Rating && 1 > data.PublicRating.Distribution[data.Rating-1] {\n\t\t\t\treturn nil, false, 0, errors.New(\"invalid public rating returned by cloud server\")\n\t\t\t}\n\t\t\tif !bazaar.ApplyBazaarPackageRating(packageName, data.PublicRating) {\n\t\t\t\treturn nil, false, 0, errors.New(\"invalid public rating returned by cloud server\")\n\t\t\t}\n\t\t\trating, ratingAvailable = bazaar.GetCachedBazaarPackageRating(packageName)\n\t\t\tif !ratingAvailable || nil == rating {\n\t\t\t\treturn nil, false, 0, errors.New(\"invalid public rating returned by cloud server\")\n\t\t\t}\n\t\t\treturn rating, true, data.Rating, nil\n\t\t}\n\t} else if nil != data.PublicRating {\n\t\treturn nil, false, 0, errors.New(\"invalid public rating returned by cloud server\")\n\t}\n\tif 5 != len(data.Distribution) {\n\t\treturn nil, false, 0, errors.New(\"invalid rating distribution returned by cloud server\")\n\t}\n\tdistribution := [5]int64(data.Distribution)\n\tif 0 < data.Rating && 1 > distribution[data.Rating-1] {\n\t\treturn nil, false, 0, errors.New(\"invalid rating distribution returned by cloud server\")\n\t}\n\tif !bazaar.ApplyBazaarPackageRatingDistribution(region, packageName, distribution) {\n\t\treturn nil, false, 0, errors.New(\"invalid rating distribution returned by cloud server\")\n\t}\n\n\trating, ratingAvailable = bazaarRatingAfterUpdate(ctx, region, packageName, distribution)\n\treturn rating, ratingAvailable, data.Rating, nil\n}\n\nfunc validateBazaarPackageRatingRequest0(ctx context.Context, pkgType, packageName string) (token string, err error) {\n\tif !isValidBazaarPackageType(pkgType) {\n\t\treturn \"\", errors.New(\"invalid package type\")\n\t}\n\tif !bazaar.IsValidPackageName(packageName) {","sourceCodeStart":182,"sourceCodeEnd":218,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/model/bazaar_rating.go#L182-L218","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Retry after a short delay so the server aggregate includes the new vote and returns a full 5-element distribution","Ensure the package is installed and present in the local bazaar cache so ApplyBazaarPackageRatingDistribution can persist","Verify region configuration (util.CurrentCloudRegion) and use the official endpoint for that region","Upgrade kernel/cloud components to matching versions; restart the kernel to rebuild caches if state is suspect"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"len(dist) == 5 && (userRating == 0 || dist[userRating-1] >= 1)","typeGuard":"func validDistribution(dist []int64, userRating int) bool {\n    return len(dist) == 5 && (userRating == 0 || dist[userRating-1] >= 1)\n}","tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"invalid rating distribution returned by cloud server\") {\n    // backoff-retry; ensure package installed and region endpoint correct\n}","preventionTips":["Backoff-retry: distributions can briefly lag a just-submitted vote","Confirm the package is installed so the distribution can be applied locally","Use the official endpoint for the configured cloud region","Match kernel/cloud versions to avoid partial-payload protocol drift"],"tags":["bazaar","cloud-api","schema","distribution"],"backgroundTag":"schema-validation-failed","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}