{"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":212,"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":194,"sourceCodeEnd":230,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/bazaar_rating.go#L194-L230","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Verify the cloud endpoint returns a proper distribution array of exactly 5 integers for the package","Update the SiYuan client to match the current cloud API response schema","Check network middleboxes/proxies that might strip or alter response JSON","Retry — if the server returned a transient error body shaped as success, a later request may succeed"],"exampleFix":"// before\nif 5 != len(data.Distribution) {\n    return nil, false, 0, errors.New(\"invalid rating distribution returned by cloud server\")\n}\n// after: log the offending payload for diagnosis\nif 5 != len(data.Distribution) {\n    logging.LogWarnf(\"unexpected distribution length %d for %s\", len(data.Distribution), packageName)\n    return nil, false, 0, errors.New(\"invalid rating distribution returned by cloud server\")\n}","handlingStrategy":"validation","validationCode":"if len(data.Distribution) != 5 { return errors.New(\"cloud distribution must contain exactly 5 star buckets\") }","typeGuard":null,"tryCatchPattern":"_, _, _, err := model.SetBazaarPackageRating(ctx, pkgType, name, userRating)\nif err != nil && strings.Contains(err.Error(), \"invalid rating distribution\") {\n    logging.LogWarnf(\"bad distribution payload for %s\", name)\n    return err\n}","preventionTips":["Verify the cloud endpoint serves a 5-element distribution array for the package","Update the SiYuan client when the cloud API schema changes","Check proxies/middleboxes that could truncate JSON fields","Confirm the cloud returns HTTP 200 with a real data payload, not an empty success"],"tags":["go","cloud-server","marketplace","rating","response-validation"],"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"}