Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit 8b8cc35

Browse files
committed
Catch and log initialization errors
1 parent b4d3a18 commit 8b8cc35

File tree

1 file changed

+83
-60
lines changed

1 file changed

+83
-60
lines changed

src/GitHub.Api/Application/ApplicationManagerBase.cs

Lines changed: 83 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -51,62 +51,70 @@ public void Run()
5151

5252
var thread = new Thread(obj =>
5353
{
54+
GitInstallationState state = new GitInstallationState();
5455
CancellationToken token = (CancellationToken)obj;
55-
SetupMetrics(Environment.UnityVersion, firstRun, instanceId);
56-
57-
if (Environment.IsMac)
56+
try
5857
{
59-
var getEnvPath = new SimpleProcessTask(token, "bash".ToNPath(), "-c \"/usr/libexec/path_helper\"")
60-
.Configure(ProcessManager, dontSetupGit: true)
61-
.Catch(e => true); // make sure this doesn't throw if the task fails
62-
var path = getEnvPath.RunWithReturn(true);
63-
if (getEnvPath.Successful)
58+
SetupMetrics(Environment.UnityVersion, firstRun, instanceId);
59+
60+
if (Environment.IsMac)
6461
{
65-
Logger.Trace("Existing Environment Path Original:{0} Updated:{1}", Environment.Path, path);
66-
Environment.Path = path?.Split(new[] { "\"" }, StringSplitOptions.None)[1];
62+
var getEnvPath = new SimpleProcessTask(token, "bash".ToNPath(), "-c \"/usr/libexec/path_helper\"")
63+
.Configure(ProcessManager, dontSetupGit: true)
64+
.Catch(e => true); // make sure this doesn't throw if the task fails
65+
var path = getEnvPath.RunWithReturn(true);
66+
if (getEnvPath.Successful)
67+
{
68+
Logger.Trace("Existing Environment Path Original:{0} Updated:{1}", Environment.Path, path);
69+
Environment.Path = path?.Split(new[] { "\"" }, StringSplitOptions.None)[1];
70+
}
6771
}
68-
}
6972

70-
GitInstallationState state = new GitInstallationState();
71-
bool skipInstallers = false;
72-
state = SystemSettings.Get<GitInstallationState>(Constants.GitInstallationState) ?? state;
73-
var now = DateTimeOffset.Now;
74-
if (now.Date == state.GitLastCheckTime.Date && state.GitIsValid && state.GitLfsIsValid)
75-
{
76-
// just check if the git/git lfs version is what we need
77-
if (firstRun)
73+
bool skipInstallers = false;
74+
state = SystemSettings.Get<GitInstallationState>(Constants.GitInstallationState) ?? state;
75+
var now = DateTimeOffset.Now;
76+
if (now.Date == state.GitLastCheckTime.Date && state.GitIsValid && state.GitLfsIsValid)
7877
{
79-
var version = new GitVersionTask(token)
80-
.Configure(ProcessManager, state.GitExecutablePath, dontSetupGit: true)
81-
.Catch(e => true)
82-
.RunWithReturn(true);
83-
state.GitIsValid = version >= Constants.MinimumGitVersion;
84-
if (state.GitIsValid)
78+
// just check if the git/git lfs version is what we need
79+
if (firstRun)
8580
{
86-
version = new GitLfsVersionTask(token)
87-
.Configure(ProcessManager, state.GitLfsExecutablePath, dontSetupGit: true)
88-
.Catch(e => true)
89-
.RunWithReturn(true);
90-
state.GitLfsIsValid = version >= Constants.MinimumGitLfsVersion;
81+
var version = new GitVersionTask(token)
82+
.Configure(ProcessManager, state.GitExecutablePath, dontSetupGit: true)
83+
.Catch(e => true)
84+
.RunWithReturn(true);
85+
state.GitIsValid = version >= Constants.MinimumGitVersion;
86+
if (state.GitIsValid)
87+
{
88+
version = new GitLfsVersionTask(token)
89+
.Configure(ProcessManager, state.GitLfsExecutablePath, dontSetupGit: true)
90+
.Catch(e => true)
91+
.RunWithReturn(true);
92+
state.GitLfsIsValid = version >= Constants.MinimumGitLfsVersion;
93+
}
9194
}
9295
}
93-
}
9496

95-
if (!skipInstallers)
96-
{
97-
Environment.OctorunScriptPath = new OctorunInstaller(Environment, TaskManager)
98-
.SetupOctorunIfNeeded();
97+
if (!skipInstallers)
98+
{
99+
Environment.OctorunScriptPath = new OctorunInstaller(Environment, TaskManager)
100+
.SetupOctorunIfNeeded();
99101

100-
state = new GitInstaller(Environment, ProcessManager, CancellationToken, SystemSettings)
101-
{ Progress = progressReporter }
102-
.SetupGitIfNeeded();
103-
}
102+
state = new GitInstaller(Environment, ProcessManager, CancellationToken, SystemSettings)
103+
{ Progress = progressReporter }
104+
.SetupGitIfNeeded();
105+
}
104106

105-
SetupGit(state);
107+
SetupGit(state);
106108

107-
if (state.GitIsValid && state.GitLfsIsValid)
109+
if (state.GitIsValid && state.GitLfsIsValid)
110+
{
111+
RestartRepository();
112+
}
113+
114+
}
115+
catch (Exception ex)
108116
{
109-
RestartRepository();
117+
Logger.Error(ex, "A problem ocurred setting up Git");
110118
}
111119

112120
new ActionTask<bool>(token, (s, gitIsValid) =>
@@ -185,28 +193,43 @@ public void SetupGit(GitInstaller.GitInstallationState state)
185193

186194
public void InitializeRepository()
187195
{
196+
isBusy = true;
188197
var thread = new Thread(obj =>
189198
{
199+
var success = true;
190200
CancellationToken token = (CancellationToken)obj;
191-
var targetPath = NPath.CurrentDirectory;
192-
193-
var gitignore = targetPath.Combine(".gitignore");
194-
var gitAttrs = targetPath.Combine(".gitattributes");
195-
var assetsGitignore = targetPath.Combine("Assets", ".gitignore");
196-
197-
var filesForInitialCommit = new List<string> { gitignore, gitAttrs, assetsGitignore };
201+
try
202+
{
203+
var targetPath = NPath.CurrentDirectory;
204+
205+
var gitignore = targetPath.Combine(".gitignore");
206+
var gitAttrs = targetPath.Combine(".gitattributes");
207+
var assetsGitignore = targetPath.Combine("Assets", ".gitignore");
208+
209+
var filesForInitialCommit = new List<string> { gitignore, gitAttrs, assetsGitignore };
210+
211+
GitClient.Init().RunWithReturn(true);
212+
GitClient.LfsInstall().RunWithReturn(true);
213+
AssemblyResources.ToFile(ResourceType.Generic, ".gitignore", targetPath, Environment);
214+
AssemblyResources.ToFile(ResourceType.Generic, ".gitattributes", targetPath, Environment);
215+
assetsGitignore.CreateFile();
216+
GitClient.Add(filesForInitialCommit).RunWithReturn(true);
217+
GitClient.Commit("Initial commit", null).RunWithReturn(true);
218+
Environment.InitializeRepository();
219+
UsageTracker.IncrementProjectsInitialized();
220+
}
221+
catch (Exception ex)
222+
{
223+
Logger.Error(ex, "A problem ocurred initializing the repository");
224+
success = false;
225+
}
198226

199-
GitClient.Init().RunWithReturn(true);
200-
GitClient.LfsInstall().RunWithReturn(true);
201-
AssemblyResources.ToFile(ResourceType.Generic, ".gitignore", targetPath, Environment);
202-
AssemblyResources.ToFile(ResourceType.Generic, ".gitattributes", targetPath, Environment);
203-
assetsGitignore.CreateFile();
204-
GitClient.Add(filesForInitialCommit).RunWithReturn(true);
205-
GitClient.Commit("Initial commit", null).RunWithReturn(true);
206-
Environment.InitializeRepository();
207-
RestartRepository();
208-
UsageTracker.IncrementProjectsInitialized();
209-
TaskManager.RunInUI(InitializeUI);
227+
if (success)
228+
{
229+
RestartRepository();
230+
TaskManager.RunInUI(InitializeUI);
231+
}
232+
isBusy = false;
210233
});
211234
thread.Start(CancellationToken);
212235
}

0 commit comments

Comments
 (0)