{"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":127,"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":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/afa823b6b4e4f183511e0bc0a3be93caa94c7c97/kernel/model/bazaar_rating.go#L109-L145","documentation":"Error returned by model.GetBazaarPackageRating (kernel/model/bazaar_rating.go:127) when the cloud's getBazaarPackageRating response carries a user rating outside the valid 0..5 range. The kernel validates the echoed data.Rating after a successful (HTTP 200, code 0) request; a negative or >5 value means the server violated its contract, and the kernel refuses to propagate garbage to callers.","triggerScenarios":"A successful call to /api/bazaar/getBazaarPackageRating where the cloud payload's rating field is malformed (e.g. -1, 6, or a parsing artifact from a changed response schema). Purely server-side; no local input can cause it.","commonSituations":"Cloud schema changes deployed ahead of the kernel; corrupted account state server-side returning sentinel values like -1 for 'no rating yet' in an old format; API version skew between an outdated kernel and a newer backend.","solutions":["Retry after a short wait to rule out a transient bad payload","Update SiYuan so the kernel's response schema matches the current cloud API","If it persists on the latest version, report it as a backend bug; there is no local workaround"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"_, _, _, err := model.GetBazaarPackageRating(ctx, pkgType, name)\nif err != nil && strings.Contains(err.Error(), \"invalid user rating returned by cloud server\") {\n    // transient backend issue: single delayed retry, else hide the rating UI\n}","preventionTips":["Do not attempt to 'fix' the value locally; the kernel already rejects the bad payload","Keep the kernel updated so response-schema validation matches the live backend"],"tags":["marketplace","ratings","cloud","contract-violation","server-response"],"backgroundTag":"invalid-server-response","analyzedSha":"afa823b6b4e4f183511e0bc0a3be93caa94c7c97","analyzedAt":"2026-08-18T17:04:10.865Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}