siyuan-note/siyuan · error

invalid bazaar rating region

Error message

invalid bazaar rating region

What it means

Thrown by fetchBazaarRatingRegion when the requested marketplace rating region index is negative or >= bazaarRatingRegionCount. Regions index into bazaarRatingRegionFiles, whose length defines the valid range, so an out-of-range index has no corresponding rating data file.

Source

Thrown at kernel/bazaar/rating.go:409

	cache.mu.RLock()
	defer cache.mu.RUnlock()
	ret.loaded = cache.loaded
	fresh = cache.loaded && now.Before(cache.expiresAt)
	if !cache.loaded {
		return
	}
	ret.data = cloneBazaarRatingDistributions(cache.data)
	for packageName, override := range cache.overrides {
		if now.Before(override.expiresAt) {
			ret.data[packageName] = override.distribution
		}
	}
	return
}

func fetchBazaarRatingRegion(ctx context.Context, region int) (ret map[string]bazaarRatingDistribution, err error) {
	if region < 0 || bazaarRatingRegionCount <= region {
		return nil, errors.New("invalid bazaar rating region")
	}

	timeBucket := bazaarRatingNow().Unix() / int64(bazaarRatingCDNBucket/time.Second)
	u := fmt.Sprintf("%s/bazaar/ratings/v1/%s?t=%d", bazaarRatingStatServer, bazaarRatingRegionFiles[region], 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)
	}

	ret, err = parseBazaarRatingRegion(buf.Bytes())
	return
}

func parseBazaarRatingRegion(data []byte) (ret map[string]bazaarRatingDistribution, err error) {

View on GitHub (pinned to 8641553a1f)

Solutions

  1. Clamp or validate the region index against bazaarRatingRegionCount before calling: 0 <= region < bazaarRatingRegionCount.
  2. If the index comes from user input or config, parse and bounds-check it, defaulting to a valid region on error.
  3. If region files were added or removed, update callers so their indices match the new bazaarRatingRegionFiles list.
  4. Fix off-by-one loops to use region < bazaarRatingRegionCount, not <=.

Example fix

// before
fetchBazaarRatingRegion(ctx, 5) // hardcoded, out of range
// after
if region < 0 || region >= bazaarRatingRegionCount {
    region = 0 // or return a validation error upstream
}
fetchBazaarRatingRegion(ctx, region)
Defensive patterns

Strategy: validation

Validate before calling

// Go: bounds-check the region before fetching
func validRegion(r int) bool { return r >= 0 && r < bazaarRatingRegionCount }

Try / catch

if dists, err := fetchBazaarRatingRegion(ctx, region); err != nil {
    if strings.Contains(err.Error(), "invalid bazaar rating region") {
        return errors.New("region index out of range; must be 0 <= region < bazaarRatingRegionCount")
    }
    return err
}

Prevention

When it happens

Trigger: Calling fetchBazaarRatingRegion (exposed for testing via TestFetchBazaarRatingRegion) with region < 0 or region >= the number of entries in bazaarRatingRegionFiles. Any code path computing a region index from user input or config can pass an invalid value.

Common situations: A test or caller hardcoding a region index beyond the number of region files after the file list changed; computing the index with an off-by-one (using length instead of length-1); parsing a user-supplied region number without bounds checking.

Related errors


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