{"record":{"id":"18a741d7a2995908","repo":"siyuan-note/siyuan","slug":"invalid-bazaar-downloads-s","errorCode":null,"errorMessage":"invalid bazaar downloads: %s","messagePattern":"invalid bazaar downloads: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/bazaar/index.go","lineNumber":264,"sourceCode":"\t} else if hasPackages {\n\t\treturn nil, errors.New(\"incomplete bazaar index metadata\")\n\t}\n\n\tif !hasMeta || 2 == ret.meta.Schema || bazaarIndexSchema < ret.meta.Schema {\n\t\tfor rawRepo, rawStats := range raw {\n\t\t\tif \"meta\" == rawRepo || \"packages\" == rawRepo {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\trepo, valid := normalizeLegacyBazaarRepo(rawRepo)\n\t\t\tif !valid {\n\t\t\t\treturn nil, fmt.Errorf(\"invalid bazaar repository: %s\", rawRepo)\n\t\t\t}\n\t\t\tstats := &bazaarStats{}\n\t\t\tif err = json.Unmarshal(rawStats, stats); nil != err {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t\tif 0 > stats.Downloads {\n\t\t\t\treturn nil, fmt.Errorf(\"invalid bazaar downloads: %s\", rawRepo)\n\t\t\t}\n\t\t\tif current := ret.legacyStats[repo]; nil != current {\n\t\t\t\tif stats.Downloads > int(^uint(0)>>1)-current.Downloads {\n\t\t\t\t\treturn nil, fmt.Errorf(\"bazaar downloads overflow: %s\", repo)\n\t\t\t\t}\n\t\t\t\tcurrent.Downloads += stats.Downloads\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tret.legacyStats[repo] = stats\n\t\t}\n\t}\n\treturn\n}\n\nfunc normalizeLegacyBazaarRepo(repo string) (string, bool) {\n\tconst githubPrefix = \"https://github.com/\"\n\tif strings.HasPrefix(repo, githubPrefix) {\n\t\trepo = strings.TrimPrefix(repo, githubPrefix)","sourceCodeStart":246,"sourceCodeEnd":282,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/bazaar/index.go#L246-L282","documentation":"In the legacy index section each repo key maps to a stats object whose 'downloads' count must be non-negative. parseBazaarIndex throws this when a stats object unmarshals with a negative Downloads value.","triggerScenarios":"An index JSON contains e.g. {\"owner/repo\": {\"downloads\": -3}}; after json.Unmarshal into bazaarStats, stats.Downloads < 0 triggers the error naming the offending raw repo key.","commonSituations":"Upstream stat server bug or manual edit producing negative counters; a mirror aggregating deltas incorrectly; corrupted cached JSON.","solutions":["Re-fetch the index from the official bazaar stat server; a negative count indicates bad upstream/cache data","If you operate a mirror, clamp or fix the aggregation so downloads counters never go negative","Locate the repo named in the error and correct its 'downloads' field to a non-negative integer"],"exampleFix":"// before\n{\"siyuan-note/foo\": {\"downloads\": -12}}\n// after\n{\"siyuan-note/foo\": {\"downloads\": 0}}","handlingStrategy":"validation","validationCode":"for repo, stats := range legacyStats {\n\tif stats.Downloads < 0 {\n\t\treturn fmt.Errorf(\"negative downloads for %s\", repo)\n\t}\n}","typeGuard":null,"tryCatchPattern":"snapshot, err := parseBazaarIndex(data)\nif err != nil {\n\tif strings.HasPrefix(err.Error(), \"invalid bazaar downloads:\") {\n\t\tlog.Errorf(\"corrupt download counters; refetch index\")\n\t}\n\treturn err\n}","preventionTips":["Clamp download counters to >= 0 at the aggregation source","Never hand-edit published index JSON","Monitor mirrors for counter regressions","Refetch from the official stat server when counters look implausible"],"tags":["bazaar","marketplace","validation","downloads","range"],"backgroundTag":"value-out-of-range","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}