{"record":{"id":"b5bcc235623a8982","repo":"siyuan-note/siyuan","slug":"invalid-bazaar-index-packages","errorCode":null,"errorMessage":"invalid bazaar index packages","messagePattern":"invalid bazaar index packages","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/bazaar/index.go","lineNumber":231,"sourceCode":"\t\t\treturn nil, err\n\t\t}\n\t\tif 2 > ret.meta.Schema {\n\t\t\treturn nil, fmt.Errorf(\"invalid bazaar index schema: %d\", ret.meta.Schema)\n\t\t}\n\t\tif \"\" == strings.TrimSpace(ret.meta.Generation) || 1 > ret.meta.PublishedAt {\n\t\t\treturn nil, errors.New(\"invalid bazaar index generation metadata\")\n\t\t}\n\t\tif bazaarIndexSchema < ret.meta.Schema {\n\t\t\tret.meta.RatingsAvailable = false\n\t\t} else {\n\t\t\tif !hasPackages {\n\t\t\t\treturn nil, errors.New(\"incomplete bazaar index metadata\")\n\t\t\t}\n\t\t\tif err = json.Unmarshal(packagesRaw, &ret.packages); nil != err {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t\tif nil == ret.packages {\n\t\t\t\treturn nil, errors.New(\"invalid bazaar index packages\")\n\t\t\t}\n\t\t\tfor packageName, pkg := range ret.packages {\n\t\t\t\tif !IsValidPackageName(packageName) || nil == pkg || !isValidBazaarRepo(pkg.Repo) || 0 > pkg.Downloads {\n\t\t\t\t\treturn nil, fmt.Errorf(\"invalid bazaar index package: %s\", packageName)\n\t\t\t\t}\n\t\t\t\tif nil != pkg.Rating {\n\t\t\t\t\trating, valid := normalizePackageRating(pkg.Rating)\n\t\t\t\t\tif !valid {\n\t\t\t\t\t\treturn nil, fmt.Errorf(\"invalid bazaar package rating: %s\", packageName)\n\t\t\t\t\t}\n\t\t\t\t\tpkg.Rating = rating\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t} else if hasPackages {\n\t\treturn nil, errors.New(\"incomplete bazaar index metadata\")\n\t}\n","sourceCodeStart":213,"sourceCodeEnd":249,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/bazaar/index.go#L213-L249","documentation":"For supported-schema indexes, the raw `packages` JSON must unmarshal into a non-nil map of package name to package entry. If json.Unmarshal leaves ret.packages nil (payload is the literal `null`) the parser rejects it. This is distinct from the raw-level null check, which only guards the top-level object.","triggerScenarios":"fetchBazaarIndexPath gets an index where \"packages\" is the JSON literal null rather than an object; a fixture with \"packages\": null.","commonSituations":"An index generator serialized a nil packages map, emitting `null`; template rendering with an unset variable produced null.","solutions":["Fix the index generator to always emit a JSON object (use {} when there are no packages)","Re-fetch the index from the official endpoint","Change the fixture to \"packages\": {}"],"exampleFix":"// before\n{\"meta\":{\"schema\":2,\"generation\":\"g1\",\"publishedAt\":1789000000},\"packages\":null}\n// after\n{\"meta\":{\"schema\":2,\"generation\":\"g1\",\"publishedAt\":1789000000},\"packages\":{}}","handlingStrategy":"validation","validationCode":"if (idx.packages === null || idx.packages === undefined || typeof idx.packages !== \"object\") throw new Error(\"packages must be a JSON object, not null\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Serialize packages with an always-initialized map so nil emits {}","Guard index generation against unset package collections","Test the zero-packages case in index builders"],"tags":["bazaar","json","validation","null-payload"],"backgroundTag":"schema-validation-failed","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"}