{"record":{"id":"26aa4d1d870775ca","repo":"siyuan-note/siyuan","slug":"invalid-public-rating-returned-by-cloud-server","errorCode":null,"errorMessage":"invalid public rating returned by cloud server","messagePattern":"invalid public rating returned by cloud server","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/bazaar_rating.go","lineNumber":164,"sourceCode":"\t}\n\n\tregion := util.CurrentCloudRegion\n\tdata := bazaarPackageSetRatingData{}\n\terr = requestBazaarPackageRating(ctx, \"/apis/siyuan/bazaar/setBazaarPackageRating\", map[string]any{\n\t\t\"token\":       token,\n\t\t\"packageName\": packageName,\n\t\t\"rating\":      userRating,\n\t}, &data)\n\tif nil != err {\n\t\treturn nil, false, 0, err\n\t}\n\tif data.Rating != userRating {\n\t\treturn nil, false, 0, errors.New(\"invalid user rating returned by cloud server\")\n\t}\n\tif nil != data.RatingAvailable {\n\t\tif !*data.RatingAvailable {\n\t\t\tif nil != 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\tif 0 == len(data.Distribution) {\n\t\t\t\treturn nil, false, data.Rating, nil\n\t\t\t}\n\t\t} else {\n\t\t\tif nil == data.PublicRating {\n\t\t\t\tif 0 != data.Rating || !bazaar.ClearBazaarPackageRating(packageName) {\n\t\t\t\t\treturn nil, false, 0, errors.New(\"invalid public rating returned by cloud server\")\n\t\t\t\t}\n\t\t\t\trating, ratingAvailable = bazaar.GetCachedBazaarPackageRating(packageName)\n\t\t\t\tif !ratingAvailable || nil != rating {\n\t\t\t\t\treturn nil, false, 0, errors.New(\"invalid public rating returned by cloud server\")\n\t\t\t\t}\n\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}","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/afa823b6b4e4f183511e0bc0a3be93caa94c7c97/kernel/model/bazaar_rating.go#L146-L182","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Retry the rating submission after a short delay so the backend reaches a consistent state","Update to the latest kernel version if the response schema changed","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"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"_, _, _, err := model.SetBazaarPackageRating(ctx, pkgType, name, stars)\nif err != nil && strings.Contains(err.Error(), \"invalid public rating returned by cloud server\") {\n    // backend payload inconsistent: single delayed retry; on repeat, report upstream and keep cache untouched\n}","preventionTips":["Treat these as backend contract violations: never mutate local caches to 'make it work'","Pin the kernel version in step with cloud API changes (update the app) to avoid schema skew"],"tags":["marketplace","ratings","cloud","contract-violation","cache-consistency","server-response"],"backgroundTag":"invalid-server-response","analyzedSha":"afa823b6b4e4f183511e0bc0a3be93caa94c7c97","analyzedAt":"2026-08-18T17:04:10.865Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}