{"record":{"id":"f236e47313f902f1","repo":"siyuan-note/siyuan","slug":"stage-index-is-unavailable","errorCode":null,"errorMessage":"stage index is unavailable","messagePattern":"stage index is unavailable","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/bazaar/stage.go","lineNumber":280,"sourceCode":"\t\t}\n\t})\n\treturn stageIndex.reposByURL[url]\n}\n\n// HasBazaarPackage 判断指定名称是否存在于官方集市 Stage 索引中。\nfunc HasBazaarPackage(ctx context.Context, pkgType, packageName string) (bool, error) {\n\tpackageNames, err := GetExistingBazaarPackageNames(ctx, pkgType, []string{packageName})\n\treturn 0 < len(packageNames), err\n}\n\n// GetExistingBazaarPackageNames 筛选存在于官方集市 Stage 索引中的包名。\nfunc GetExistingBazaarPackageNames(ctx context.Context, pkgType string, packageNames []string) ([]string, error) {\n\tstageIndex, err := getStageIndex(ctx, pkgType)\n\tif nil != err {\n\t\treturn nil, err\n\t}\n\tif nil == stageIndex {\n\t\treturn nil, errors.New(\"stage index is unavailable\")\n\t}\n\tofficial := make(map[string]bool, len(stageIndex.Repos))\n\tfor _, repo := range stageIndex.Repos {\n\t\tif nil != repo && nil != repo.Package {\n\t\t\tofficial[repo.Package.Name] = true\n\t\t}\n\t}\n\tret := make([]string, 0, len(packageNames))\n\tfor _, packageName := range packageNames {\n\t\tif official[packageName] {\n\t\t\tret = append(ret, packageName)\n\t\t}\n\t}\n\treturn ret, nil\n}\n\n// bazaarStats 集市包统计信息\ntype bazaarStats struct {","sourceCodeStart":262,"sourceCodeEnd":298,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/bazaar/stage.go#L262-L298","documentation":"GetExistingBazaarPackageNames filters the requested package names against the official stage index. It calls getStageIndex first; if that succeeds but returns a nil index (a defensive branch), it returns this sentinel error. It also propagates any error from getStageIndex unchanged.","triggerScenarios":"Calling GetExistingBazaarPackageNames (e.g. through HasBazaarPackage) when the stage index cannot be fetched — rhy hash unavailable, OSS non-200, or the nil-index defensive branch fires.","commonSituations":"Offline environment or blocked rhy/OSS endpoints; stale bazaar hash; rhy/OSS outages while checking whether a package exists before install/update.","solutions":["Treat this as a symptom of getStageIndex failing — check kernel logs for the preceding 'bazaar hash unavailable' or 'get community stage index' lines","Restore connectivity to rhy and BazaarOSSServer, then retry","If the nil-index branch fires repeatedly, inspect getStageIndex's SetSuccessResult handling for unmarshal issues","For install/update flows, surface 'marketplace index unavailable' and let the user retry rather than failing silently"],"exampleFix":"// before\nif nil == stageIndex {\n    return nil, errors.New(\"stage index is unavailable\")\n}\n// after (log which pkgType failed for easier triage)\nif nil == stageIndex {\n    logging.LogErrorf(\"stage index for %s is unavailable\", pkgType)\n    return nil, fmt.Errorf(\"stage index is unavailable for %s\", pkgType)\n}","handlingStrategy":"fallback","validationCode":"// pre-check marketplace metadata availability before querying packages\nif util.GetRhyBazaarHash(ctx) == \"\" {\n    return errors.New(\"marketplace metadata currently unavailable\")\n}","typeGuard":null,"tryCatchPattern":"names, err := GetExistingBazaarPackageNames(ctx, \"plugins\", []string{\"foo\"})\nif err != nil && strings.Contains(err.Error(), \"stage index\") {\n    // fall back to locally installed package list\n}","preventionTips":["Do not assume network availability when checking marketplace packages; always handle the error","Maintain a local cache of previously fetched stage indexes for fallback","Log pkgType and hash with the failure to speed up diagnosis"],"tags":["network","bazaar","index"],"backgroundTag":"resource-not-found","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}