{"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/8641553a1f07374001902d3ce773285db1292b2d/kernel/bazaar/index.go#L213-L249","documentation":"The index's \"packages\" key unmarshalled to a null map — i.e. the JSON literally contains \"packages\": null. A valid index needs a non-null packages object (possibly empty) for the parser to iterate; null means the publisher serialized a nil map.","triggerScenarios":"parseBazaarIndex encounters {\"meta\": {...}, \"packages\": null} with a compatible schema — json.Unmarshal leaves ret.packages as nil and the explicit nil check fires.","commonSituations":"Server-side Go publisher marshalling a nil map[string]*bazaarIndexPackage; a migration or deploy step resetting the packages field; hand-edited or generated fixture with an explicit null.","solutions":["Fix the publisher to never marshal a nil packages map — initialize it (empty map is valid) before serialization","Republish the index with \"packages\": {} at minimum if the marketplace is genuinely empty","Add a pre-publish validation rejecting null packages","Retry after the server-side fix; the client caches the last good snapshot meanwhile"],"exampleFix":"// publisher, before\nvar packages map[string]*Package // nil when nothing added\njson.Marshal(idx) // \"packages\": null\n// after\npackages = map[string]*Package{}\njson.Marshal(idx) // \"packages\": {}","handlingStrategy":"validation","validationCode":"// pre-publish check\nvar idx struct{ Packages map[string]json.RawMessage `json:\"packages\"` }\njson.Unmarshal(body, &idx)\nif idx.Packages == nil {\n    return errors.New(\"packages must be an object, not null\")\n}","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"invalid bazaar index packages\") {\n    // publisher marshalled a nil map; keep cached snapshot and fix server\n}","preventionTips":["Initialize package maps to empty (not nil) before marshalling in the publisher","Add a serializer test asserting \"packages\": {} appears when there are no packages","Reject null in the publish pipeline's JSON lint step"],"tags":["marketplace","json","null"],"backgroundTag":"unexpected-api-response-shape","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"}