siyuan-note/siyuan · error

invalid null bazaar index

Error message

invalid null bazaar index

What it means

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.

Solutions

  1. Check the HTTP response body of the bazaar index endpoint for `null` or empty content and retry the fetch
  2. Delete the stale cached index file so the next fetch downloads fresh data
  3. Fix the test fixture to contain a valid JSON object (at minimum `{}` or a legacy stats map)

Example fix

// before
const idx = null
parseBazaarIndex(idx)
// after
const idx = {"meta":{"schema":2,"generation":"g1","publishedAt":1717000000},"packages":{}}
parseBazaarIndex(idx)
Defensive patterns

Strategy: validation

Validate before calling

const trimmed = raw.trim()
if (trimmed.length === 0 || trimmed === "null") throw new Error("empty bazaar index payload")

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/e6e8022933d219db. Report an issue: GitHub.

Appendix: source

Thrown at kernel/bazaar/index.go:202

	u := fmt.Sprintf("%s%s?t=%d", bazaarIndexStatServer, indexPath, timeBucket)
	buf := &bytes.Buffer{}
	resp, err := httpclient.NewBrowserRequest().SetRetryCount(0).SetContext(ctx).SetOutput(buf).Get(u)
	if nil != err {
		return nil, err
	}
	if 200 != resp.StatusCode {
		return nil, fmt.Errorf("unexpected status code: %d", resp.StatusCode)
	}
	return parseBazaarIndex(buf.Bytes())
}

func parseBazaarIndex(data []byte) (ret *bazaarIndexSnapshot, err error) {
	raw := map[string]json.RawMessage{}
	if err = json.Unmarshal(data, &raw); nil != err {
		return nil, err
	}
	if nil == raw {
		return nil, errors.New("invalid null bazaar index")
	}
	ret = &bazaarIndexSnapshot{
		packages:    map[string]*bazaarIndexPackage{},
		legacyStats: map[string]*bazaarStats{},
	}

	metaRaw, hasMeta := raw["meta"]
	packagesRaw, hasPackages := raw["packages"]
	if hasMeta {
		if err = json.Unmarshal(metaRaw, &ret.meta); nil != err {
			return nil, err
		}
		if 2 > ret.meta.Schema {
			return nil, fmt.Errorf("invalid bazaar index schema: %d", ret.meta.Schema)
		}
		if "" == strings.TrimSpace(ret.meta.Generation) || 1 > ret.meta.PublishedAt {
			return nil, errors.New("invalid bazaar index generation metadata")
		}

View on GitHub (pinned to 9f775e8a12)