{"record":{"id":"e6e8022933d219db","repo":"siyuan-note/siyuan","slug":"invalid-null-bazaar-index","errorCode":null,"errorMessage":"invalid null bazaar index","messagePattern":"invalid null bazaar index","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/bazaar/index.go","lineNumber":202,"sourceCode":"\tu := fmt.Sprintf(\"%s%s?t=%d\", bazaarIndexStatServer, indexPath, timeBucket)\n\tbuf := &bytes.Buffer{}\n\tresp, err := httpclient.NewBrowserRequest().SetRetryCount(0).SetContext(ctx).SetOutput(buf).Get(u)\n\tif nil != err {\n\t\treturn nil, err\n\t}\n\tif 200 != resp.StatusCode {\n\t\treturn nil, fmt.Errorf(\"unexpected status code: %d\", resp.StatusCode)\n\t}\n\treturn parseBazaarIndex(buf.Bytes())\n}\n\nfunc parseBazaarIndex(data []byte) (ret *bazaarIndexSnapshot, 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\tif nil == raw {\n\t\treturn nil, errors.New(\"invalid null bazaar index\")\n\t}\n\tret = &bazaarIndexSnapshot{\n\t\tpackages:    map[string]*bazaarIndexPackage{},\n\t\tlegacyStats: map[string]*bazaarStats{},\n\t}\n\n\tmetaRaw, hasMeta := raw[\"meta\"]\n\tpackagesRaw, hasPackages := raw[\"packages\"]\n\tif hasMeta {\n\t\tif err = json.Unmarshal(metaRaw, &ret.meta); nil != err {\n\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}","sourceCodeStart":184,"sourceCodeEnd":220,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/bazaar/index.go#L184-L220","documentation":"parseBazaarIndex unmarshals the downloaded bazaar index JSON into a map of raw fields. If json.Unmarshal succeeds but produces a nil map (i.e. the payload is the JSON literal `null`, or empty bytes), the parser rejects it with this error because there is no index content to work with. It is a guard against treating a degenerate response as a valid package index.","triggerScenarios":"Calling fetchBazaarIndexPath (or running the parseBazaarIndex unit tests) with input that unmarshals into a nil map: the literal bytes `null`, or whitespace-only/empty input that Go's json.Unmarshal leaves as nil for map targets.","commonSituations":"The bazaar CDN/proxy returns the body `null` or an empty 200 response; a cached index file was truncated or never written; a test fixture was saved as an empty file.","solutions":["Check the HTTP response body of the bazaar index endpoint for `null` or empty content and retry the fetch","Delete the stale cached index file so the next fetch downloads fresh data","Fix the test fixture to contain a valid JSON object (at minimum `{}` or a legacy stats map)"],"exampleFix":"// before\nconst idx = null\nparseBazaarIndex(idx)\n// after\nconst idx = {\"meta\":{\"schema\":2,\"generation\":\"g1\",\"publishedAt\":1717000000},\"packages\":{}}\nparseBazaarIndex(idx)","handlingStrategy":"validation","validationCode":"const trimmed = raw.trim()\nif (trimmed.length === 0 || trimmed === \"null\") throw new Error(\"empty bazaar index payload\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check HTTP status and body before caching fetched index data","Never persist an empty/null response body as a cached index","Validate cached index files exist and are non-empty before reading"],"tags":["json","bazaar","validation","empty-payload"],"backgroundTag":"empty-response-body","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"}