siyuan-note/siyuan · error

stage index is unavailable

Error message

stage index is unavailable

What it means

GetExistingBazaarPackageNames returns this error when getStageIndex succeeded (nil error) but returned a nil stage index. It is an internal defensive check ensuring callers never receive a nil index without an error.

Solutions

  1. Check the earlier logged error from getStageIndex — fix the underlying index-fetch failure (see errors 461/462).
  2. If developing: audit getStageIndex so every success path returns a non-nil *StageIndex.
  3. Retry the marketplace operation after network issues are resolved.
Defensive patterns

Strategy: try-catch

Type guard

if stageIndex == nil {
    return errors.New("stage index is unavailable")
}

Try / catch

names, err := GetExistingBazaarPackageNames(ctx, pkgType, pkgs)
if err != nil {
    log.Printf("cannot check existing packages: %v", err)
    return err
}

Prevention

When it happens

Trigger: HasBazaarPackage calls GetExistingBazaarPackageNames and getStageIndex returns (nil, nil) — practically a rare invariant violation, e.g. an unexpected code path or future refactor where an early return yields a nil result without setting err.

Common situations: Mostly hit during development or refactoring of kernel/bazaar when a success path accidentally skips index population; end users should normally see 461/462 instead.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


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

Appendix: source

Thrown at kernel/bazaar/stage.go:280

		}
	})
	return stageIndex.reposByURL[url]
}

// HasBazaarPackage 判断指定名称是否存在于官方集市 Stage 索引中。
func HasBazaarPackage(ctx context.Context, pkgType, packageName string) (bool, error) {
	packageNames, err := GetExistingBazaarPackageNames(ctx, pkgType, []string{packageName})
	return 0 < len(packageNames), err
}

// GetExistingBazaarPackageNames 筛选存在于官方集市 Stage 索引中的包名。
func GetExistingBazaarPackageNames(ctx context.Context, pkgType string, packageNames []string) ([]string, error) {
	stageIndex, err := getStageIndex(ctx, pkgType)
	if nil != err {
		return nil, err
	}
	if nil == stageIndex {
		return nil, errors.New("stage index is unavailable")
	}
	official := make(map[string]bool, len(stageIndex.Repos))
	for _, repo := range stageIndex.Repos {
		if nil != repo && nil != repo.Package {
			official[repo.Package.Name] = true
		}
	}
	ret := make([]string, 0, len(packageNames))
	for _, packageName := range packageNames {
		if official[packageName] {
			ret = append(ret, packageName)
		}
	}
	return ret, nil
}

// bazaarStats 集市包统计信息
type bazaarStats struct {

View on GitHub (pinned to 9f775e8a12)