{"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/9f775e8a12daef8255556097396f9b2739078892/kernel/bazaar/index.go#L246-L282","documentation":"After a legacy repository key normalizes, its stats JSON is unmarshalled and its Downloads must be >= 0; a negative value aborts parsing with the repository name in the message. Downloads counts are aggregated across aliases, and negative input would corrupt the running sum.","triggerScenarios":"fetchBazaarIndexPath receives a legacy index where <repo> maps to an object whose downloads field is negative (e.g. {\"downloads\":-5}) or of a type unmarshalling to a negative number.","commonSituations":"An upstream stats counter underflowed; a manual edit or data-migration script wrote negative counts; a fixture built with placeholder negative numbers.","solutions":["Fix the negative downloads value in the bazaar stats source","Re-fetch the index after upstream stats are corrected","Change the fixture to use a non-negative downloads value"],"exampleFix":"// before\n{\"siyuan-note/siyuan\":{\"downloads\":-5}}\n// after\n{\"siyuan-note/siyuan\":{\"downloads\":5}}","handlingStrategy":"validation","validationCode":"for (const [repo, stats] of Object.entries(idx)) {\n  if (repo !== \"meta\" && repo !== \"packages\" && typeof stats.downloads === \"number\" && stats.downloads < 0) throw new Error(`negative downloads for ${repo}`)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Clamp downloads to 0 at the stats aggregation source","Monitor upstream counters for underflow","Use non-negative placeholders in fixtures"],"tags":["bazaar","legacy-format","validation","value-out-of-range"],"backgroundTag":"value-out-of-range","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"}