babalae/better-genshin-impact · warning · InvalidOperationException
仓库文件夹不存在,请至少成功更新一次仓库!
Error message
仓库文件夹不存在,请至少成功更新一次仓库!
What it means
Thrown by RepoWebBridge.GetRepoJson when Directory.Exists(ScriptRepoUpdater.CenterRepoPath) is false. CenterRepoPath is the local clone of the script repository; it only exists after a successful first repo update. The exception is caught immediately and shown via ThemedMessageBox.ErrorAsync, then the method returns string.Empty.
Source
Thrown at BetterGenshinImpact/Core/Script/WebView/RepoWebBridge.cs:42
private static readonly HashSet<string> AllowedTextExtensions = new(StringComparer.OrdinalIgnoreCase)
{
".txt", ".md", ".json", ".js", ".ts",
".vue", ".css", ".html", ".csv", ".xml",
".yaml", ".yml", ".ini", ".config"
};
private static readonly HashSet<string> AllowedImageExtensions = new(StringComparer.OrdinalIgnoreCase)
{
".png", ".jpg", ".jpeg", ".gif", ".webp", ".svg", ".bmp", ".ico"
};
public async Task<string> GetRepoJson()
{
try
{
if (!Directory.Exists(ScriptRepoUpdater.CenterRepoPath))
{
throw new InvalidOperationException("仓库文件夹不存在,请至少成功更新一次仓库!");
}
string localRepoJsonPath = GetRepoJsonPath();
return await File.ReadAllTextAsync(localRepoJsonPath);
}
catch (Exception ex)
{
await ThemedMessageBox.ErrorAsync(ex.Message, "获取仓库信息失败");
return string.Empty;
}
}
public async void ImportUri(string url)
{
try
{
await ScriptRepoUpdater.Instance.ImportScriptFromUri(url, false);
WeakReferenceMessenger.Default.Send(new RefreshDataMessage("Refresh"));View on GitHub (pinned to a7cb36712d)
Solutions
- Trigger a repository update once (call ScriptRepoUpdater update) so CenterRepoPath is created and populated.
- Verify CenterRepoPath exists and is writable before opening the WebView page.
- If the path was customized, reset it to the default or recreate the directory and re-run the update.
- Check that the prior update did not fail due to network/git errors and retry.
Example fix
// before
var json = await bridge.GetRepoJson();
// after
if (!Directory.Exists(ScriptRepoUpdater.CenterRepoPath))
{
await ScriptRepoUpdater.Instance.UpdateAsync(ct);
}
var json = await bridge.GetRepoJson(); Defensive patterns
Strategy: validation
Validate before calling
if (!Directory.Exists(ScriptRepoUpdater.CenterRepoPath))
{
await ScriptRepoUpdater.Instance.UpdateAsync(ct);
}
if (!Directory.Exists(ScriptRepoUpdater.CenterRepoPath))
return; // still missing after update attempt Try / catch
try { var json = await bridge.GetRepoJson(); }
catch { /* GetRepoJson already shows ThemedMessageBox and returns "" */ } Prevention
- Trigger a repo update on first launch before exposing WebView actions.
- Disable repo-dependent UI until CenterRepoPath exists.
- Verify write permissions and disk space for CenterRepoPath.
When it happens
Trigger: Opening the script-repo WebView before ever clicking 'update repo'; the repo folder was deleted manually; CenterRepoPath points to a non-default location that was never created; first run of the app on a fresh profile.
Common situations: New installation with no repo sync yet; user cleared the app data directory; CenterRepoPath misconfigured in settings to a path that does not exist; repo update previously failed silently leaving no folder.
Related errors
- repo.json 仓库索引文件不存在,请至少成功更新一次仓库!
- 找不到原始 repo.json 文件
- 文件 '{relativePath}' 不存在
- 读取文件失败: {ex.Message}
- 写入文件失败: {ex.Message}
AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13).
Data as JSON: /api/errors/ba45373799c33a9b.
Report an issue: GitHub.