babalae/better-genshin-impact · error · Exception
本地仓库缺少 repo.json
Error message
本地仓库缺少 repo.json
What it means
Thrown by FindCenterRepoPath when neither a top-level repo.json nor a recursively-found repo.json exists under CenterRepoPath. The center repo manifest file is mandatory to locate scripts; without it the path cannot be resolved.
Source
Thrown at BetterGenshinImpact/Core/Script/ScriptRepoUpdater.cs:1825
if (File.Exists(repoJsonPath))
{
repoJsonDir = CenterRepoPath;
}
else
{
// 递归查找 repo.json
var localRepoJsonPath = Directory
.GetFiles(CenterRepoPath, "repo.json", SearchOption.AllDirectories).FirstOrDefault();
if (localRepoJsonPath != null)
{
repoJsonDir = Path.GetDirectoryName(localRepoJsonPath);
}
}
if (string.IsNullOrEmpty(repoJsonDir))
{
throw new Exception("本地仓库缺少 repo.json");
}
// 检查 repo.json 同级是否存在 repo/ 目录来判断仓库类型
var repoSubDir = Path.Combine(repoJsonDir, "repo");
if (Directory.Exists(repoSubDir))
{
// 存在 repo/ 目录,说明是文件式仓库
return repoSubDir;
}
else
{
// 不存在 repo/ 目录,说明是 Git 仓库
return repoJsonDir;
}
}
private (string time, string url, string file) ParseJson(string jsonString)
{View on GitHub (pinned to a7cb36712d)
Solutions
- Trigger a fresh download/clone of the center repo before calling FindCenterRepoPath (ensure the manifest exists first).
- Verify CenterRepoPath is correct and the directory is readable; check `Directory.Exists(CenterRepoPath)`.
- If repo.json exists in the Git tree but wasn't checked out to disk, run CheckoutRepoJson to materialize it before FindCenterRepoPath.
- Provide a recovery action in the error: prompt the user to re-download the center repo.
Example fix
// before
if (string.IsNullOrEmpty(repoJsonDir))
throw new Exception("本地仓库缺少 repo.json");
// after (recovery hint + path)
if (string.IsNullOrEmpty(repoJsonDir))
throw new FileNotFoundException(
$"本地仓库缺少 repo.json(搜索目录: {CenterRepoPath})。请重新下载中央仓库。",
Path.Combine(CenterRepoPath, "repo.json")); Defensive patterns
Strategy: validation
Validate before calling
// Ensure the manifest is materialized before lookup
if (!File.Exists(Path.Combine(CenterRepoPath, "repo.json")) &&
Directory.GetFiles(CenterRepoPath, "repo.json", SearchOption.AllDirectories).Length == 0)
{
// trigger download/clone to obtain repo.json
await DownloadRepoAndUnzip(centerRepoUrl);
} Try / catch
catch (FileNotFoundException ex) when (ex.Message.Contains("repo.json"))
{
UIDispatcherHelper.Invoke(() => Toast.Error("中央仓库未初始化,正在重新下载..."));
await DownloadRepoAndUnzip(centerRepoUrl);
} Prevention
- Download/clone the center repo before FindCenterRepoPath is ever called.
- Verify Directory.Exists(CenterRepoPath) and readability.
- Run CheckoutRepoJson to materialize the manifest after a Git clone.
When it happens
Trigger: FindCenterRepoPath() runs: File.Exists(CenterRepoPath/repo.json) is false, then Directory.GetFiles(CenterRepoPath, "repo.json", SearchOption.AllDirectories).FirstOrDefault() returns null, so repoJsonDir stays null.
Common situations: First run before any repo has been downloaded; a prior download/clone failed and left no repo.json; the CenterRepoPath directory was deleted or moved; permissions prevent reading the directory; the repo was cloned but HEAD pointed at a commit lacking repo.json (so checkout didn't materialize it).
Related errors
- 未找到 repo.json 文件,不是有效的脚本仓库压缩包。
- 仓库中不存在路径: {sourcePath}
- repo.json 解析失败
- 等待 {targetDescription} 超时({timeout}ms)
- 识别元素在 {actualTimeout}ms 后超时未消失!
AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13).
Data as JSON: /api/errors/0494d84d6b10ff32.
Report an issue: GitHub.