{"record":{"id":"6bd1b2f68e53fafd","repo":"siyuan-note/siyuan","slug":"invalid-user-rating-returned-by-cloud-server","errorCode":null,"errorMessage":"invalid user rating returned by cloud server","messagePattern":"invalid user rating returned by cloud server","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/bazaar_rating.go","lineNumber":143,"sourceCode":"\n// GetBazaarPackageRating 获取已安装官方包的公开评分和当前用户评分。\nfunc GetBazaarPackageRating(ctx context.Context, pkgType, packageName string) (rating *bazaar.PackageRating,\n\tratingAvailable bool, userRating int, err error) {\n\ttoken, err := bazaarRatingValidatePackage(ctx, pkgType, packageName)\n\tif nil != err {\n\t\treturn nil, false, 0, err\n\t}\n\n\tdata := bazaarPackageUserRatingData{}\n\terr = requestBazaarPackageRating(ctx, \"/apis/siyuan/bazaar/getBazaarPackageRating\", map[string]any{\n\t\t\"token\":       token,\n\t\t\"packageName\": packageName,\n\t}, &data)\n\tif nil != err {\n\t\treturn nil, false, 0, err\n\t}\n\tif 0 > data.Rating || 5 < data.Rating {\n\t\treturn nil, false, 0, errors.New(\"invalid user rating returned by cloud server\")\n\t}\n\n\trating, ratingAvailable = bazaar.GetBazaarPackageRating(ctx, packageName)\n\treturn rating, ratingAvailable, data.Rating, nil\n}\n\n// SetBazaarPackageRating 设置或取消已安装官方包的当前用户评分。\nfunc SetBazaarPackageRating(ctx context.Context, pkgType, packageName string, userRating int) (rating *bazaar.PackageRating,\n\tratingAvailable bool, retUserRating int, err error) {\n\tif 0 > userRating || 5 < userRating {\n\t\treturn nil, false, 0, errors.New(\"rating must be an integer from 0 to 5\")\n\t}\n\tbazaarRatingSetMu.Lock()\n\tdefer bazaarRatingSetMu.Unlock()\n\n\ttoken, err := bazaarRatingValidatePackage(ctx, pkgType, packageName)\n\tif nil != err {\n\t\treturn nil, false, 0, err","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/bazaar_rating.go#L125-L161","documentation":"GetBazaarPackageRating validates the cloud's response: the returned user rating must be within 0..5. If the cloud server returns a rating outside that range, the client rejects the response as corrupt/untrusted rather than propagating bad data.","triggerScenarios":"Calling GetBazaarPackageRating (or the batched requestBazaarPackageUserRatings worker) when the cloud response body contains data.rating < 0 or > 5.","commonSituations":"Cloud API schema change or regression; a middleman/proxy altering the response; region-specific cloud deployments returning unexpected payloads.","solutions":["Retry the request; a single malformed response may be transient","Verify which cloud server/region is configured and whether it matches the client version","Report the issue with the raw response so the cloud bug can be fixed"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if userRating < 0 || userRating > 5 {\n    return errors.New(\"rating from cloud outside 0..5\")\n}","typeGuard":null,"tryCatchPattern":"// Go\nrating, avail, userRating, err := model.GetBazaarPackageRating(ctx, pkgType, name)\nif err != nil {\n    // includes 'invalid user rating returned by cloud server'\n    return fmt.Errorf(\"fetch rating failed: %w\", err)\n}","preventionTips":["Validate cloud payloads at the boundary before applying them","Pin client and cloud API versions to compatible releases","Log raw responses when validation fails to ease diagnosis"],"tags":["cloud","validation","response"],"backgroundTag":"unexpected-api-response-shape","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}