{"record":{"id":"1a83eb1612cd3f1c","repo":"siyuan-note/siyuan","slug":"invalid-rating-distribution-length-for-package-s","errorCode":null,"errorMessage":"invalid rating distribution length for package: %s","messagePattern":"invalid rating distribution length for package: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/bazaar/rating.go","lineNumber":442,"sourceCode":"\treturn\n}\n\nfunc parseBazaarRatingRegion(data []byte) (ret map[string]bazaarRatingDistribution, err error) {\n\traw := map[string]json.RawMessage{}\n\tif err = json.Unmarshal(data, &raw); nil != err {\n\t\treturn nil, err\n\t}\n\tret = make(map[string]bazaarRatingDistribution, len(raw))\n\tfor packageName, rawDistribution := range raw {\n\t\tif !IsValidPackageName(packageName) {\n\t\t\treturn nil, fmt.Errorf(\"invalid package name: %s\", packageName)\n\t\t}\n\t\tvar values []int64\n\t\tif err = json.Unmarshal(rawDistribution, &values); nil != err {\n\t\t\treturn nil, err\n\t\t}\n\t\tif 5 != len(values) {\n\t\t\treturn nil, fmt.Errorf(\"invalid rating distribution length for package: %s\", packageName)\n\t\t}\n\t\tdistribution := bazaarRatingDistribution(values)\n\t\tif !validBazaarRatingDistribution(distribution) {\n\t\t\treturn nil, fmt.Errorf(\"invalid rating distribution for package: %s\", packageName)\n\t\t}\n\t\tret[packageName] = distribution\n\t}\n\treturn\n}\n\nfunc mergeBazaarRatingRegions(regions [bazaarRatingRegionCount]bazaarRatingRegionResult) map[string]*PackageRating {\n\tdistributions := map[string]bazaarRatingDistribution{}\n\tfor _, region := range regions {\n\t\tfor packageName, distribution := range region.data {\n\t\t\tmerged := distributions[packageName]\n\t\t\tvalid := true\n\t\t\tfor i, count := range distribution {\n\t\t\t\tif count > math.MaxInt64-merged[i] {","sourceCodeStart":424,"sourceCodeEnd":460,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/bazaar/rating.go#L424-L460","documentation":"After unmarshalling a package's rating distribution, parseBazaarRatingRegion requires exactly 5 values (counts for star ratings 1-5). A distribution array of any other length aborts parsing with this error naming the package. It guards against schema drift or corruption in the rating payload.","triggerScenarios":"Calling parseBazaarRatingRegion / fetchBazaarRatingRegion on JSON where some package's value array has fewer or more than 5 integers — e.g. [0,0,0,0] or a 6-element array with an extra 'unrated' bucket.","commonSituations":"Upstream changed the distribution schema (added/removed buckets); a truncated download cut off array elements; a hand-written test fixture used the wrong array length.","solutions":["Inspect the named package's distribution array in the raw JSON and compare its length to the expected 5","Fix the test/fixture data to contain exactly 5 values","If upstream changed the schema, update the parser and bazaarRatingDistribution type to the new arity","Re-fetch the payload if truncation (network/proxy) is suspected"],"exampleFix":"// before\n\"pkg\": [3, 1]\n// after\n\"pkg\": [3, 1, 0, 0, 0] // exactly five star buckets (1..5 stars)","handlingStrategy":"validation","validationCode":"var raw map[string]json.RawMessage\njson.Unmarshal(data, &raw)\nfor name, dist := range raw {\n    var values []int64\n    if json.Unmarshal(dist, &values) == nil && len(values) != 5 {\n        return fmt.Errorf(\"package %s has %d rating buckets, need 5\", name, len(values))\n    }\n}","typeGuard":"func isFiveBucketDistribution(raw json.RawMessage) bool {\n    var v []int64\n    return json.Unmarshal(raw, &v) == nil && len(v) == 5\n}","tryCatchPattern":"dist, err := parseBazaarRatingRegion(data)\nif err != nil && strings.Contains(err.Error(), \"invalid rating distribution length\") {\n    // re-fetch or skip the payload; log the package name from the error\n}","preventionTips":["Always author rating fixtures with exactly five star buckets","Check content-length/gzip integrity when downloading large rating payloads","Document and version the distribution schema the parser expects"],"tags":["validation","schema","bazaar"],"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"}