siyuan-note/siyuan · error

invalid bazaar index packages

Error message

invalid bazaar index packages

What it means

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.

Source

Thrown at kernel/bazaar/index.go:231

			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")
		}
		if bazaarIndexSchema < ret.meta.Schema {
			ret.meta.RatingsAvailable = false
		} else {
			if !hasPackages {
				return nil, errors.New("incomplete bazaar index metadata")
			}
			if err = json.Unmarshal(packagesRaw, &ret.packages); nil != err {
				return nil, err
			}
			if nil == ret.packages {
				return nil, errors.New("invalid bazaar index packages")
			}
			for packageName, pkg := range ret.packages {
				if !IsValidPackageName(packageName) || nil == pkg || !isValidBazaarRepo(pkg.Repo) || 0 > pkg.Downloads {
					return nil, fmt.Errorf("invalid bazaar index package: %s", packageName)
				}
				if nil != pkg.Rating {
					rating, valid := normalizePackageRating(pkg.Rating)
					if !valid {
						return nil, fmt.Errorf("invalid bazaar package rating: %s", packageName)
					}
					pkg.Rating = rating
				}
			}
		}
	} else if hasPackages {
		return nil, errors.New("incomplete bazaar index metadata")
	}

View on GitHub (pinned to 8641553a1f)

Solutions

  1. Fix the publisher to never marshal a nil packages map — initialize it (empty map is valid) before serialization
  2. Republish the index with "packages": {} at minimum if the marketplace is genuinely empty
  3. Add a pre-publish validation rejecting null packages
  4. Retry after the server-side fix; the client caches the last good snapshot meanwhile

Example fix

// publisher, before
var packages map[string]*Package // nil when nothing added
json.Marshal(idx) // "packages": null
// after
packages = map[string]*Package{}
json.Marshal(idx) // "packages": {}
Defensive patterns

Strategy: validation

Validate before calling

// pre-publish check
var idx struct{ Packages map[string]json.RawMessage `json:"packages"` }
json.Unmarshal(body, &idx)
if idx.Packages == nil {
    return errors.New("packages must be an object, not null")
}

Try / catch

if err != nil && strings.Contains(err.Error(), "invalid bazaar index packages") {
    // publisher marshalled a nil map; keep cached snapshot and fix server
}

Prevention

When it happens

Trigger: parseBazaarIndex encounters {"meta": {...}, "packages": null} with a compatible schema — json.Unmarshal leaves ret.packages as nil and the explicit nil check fires.

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

Understand the failure class

Background: "invalid response format", "malformed payload", "missing data field": when an API returns 200 but the response shape is wrong — this error's family across 23 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@8641553a1f (2026-09-11). Data as JSON: /api/errors/b5bcc235623a8982. Report an issue: GitHub.