Skip to content

Commit 9f4b941

Browse files
committed
logging or something who cares
1 parent 70f7c4a commit 9f4b941

File tree

3 files changed

+56
-53
lines changed

3 files changed

+56
-53
lines changed

StabilityMatrix.Core/Helper/IPrerequisiteHelper.cs

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -114,38 +114,16 @@ async Task CloneGitRepository(
114114
// If pinning to a specific commit, we need a destination directory to continue
115115
if (!string.IsNullOrWhiteSpace(version?.CommitSha))
116116
{
117-
try
118-
{
119-
await RunGit(
120-
["fetch", "--depth", "1", "origin", version.CommitSha!],
121-
onProcessOutput,
122-
rootDir
123-
)
124-
.ConfigureAwait(false);
125-
await RunGit(["checkout", "--force", version.CommitSha!], onProcessOutput, rootDir)
126-
.ConfigureAwait(false);
127-
await RunGit(
128-
["submodule", "update", "--init", "--recursive", "--depth", "1"],
129-
onProcessOutput,
130-
rootDir
131-
)
132-
.ConfigureAwait(false);
133-
}
134-
catch (ProcessException ex)
135-
{
136-
if (ex.Message.Contains("Git exited with code 128"))
137-
{
138-
onProcessOutput?.Invoke(
139-
ProcessOutput.FromStdErrLine(
140-
$"Unable to check out commit {version.CommitSha} - continuing with latest commit from {version.Branch}\n\n{ex.ProcessResult?.StandardError}\n"
141-
)
142-
);
143-
}
144-
else
145-
{
146-
throw;
147-
}
148-
}
117+
await RunGit(["fetch", "--depth", "1", "origin", version.CommitSha!], onProcessOutput, rootDir)
118+
.ConfigureAwait(false);
119+
await RunGit(["checkout", "--force", version.CommitSha!], onProcessOutput, rootDir)
120+
.ConfigureAwait(false);
121+
await RunGit(
122+
["submodule", "update", "--init", "--recursive", "--depth", "1"],
123+
onProcessOutput,
124+
rootDir
125+
)
126+
.ConfigureAwait(false);
149127
}
150128
}
151129

StabilityMatrix.Core/Models/Packages/AiToolkit.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Collections.Immutable;
22
using System.Text.RegularExpressions;
33
using Injectio.Attributes;
4+
using NLog;
45
using StabilityMatrix.Core.Extensions;
56
using StabilityMatrix.Core.Helper;
67
using StabilityMatrix.Core.Helper.Cache;
@@ -10,6 +11,7 @@
1011
using StabilityMatrix.Core.Processes;
1112
using StabilityMatrix.Core.Python;
1213
using StabilityMatrix.Core.Services;
14+
using LogLevel = Microsoft.Extensions.Logging.LogLevel;
1315

1416
namespace StabilityMatrix.Core.Models.Packages;
1517

@@ -23,6 +25,7 @@ IPyInstallationManager pyInstallationManager
2325
) : BaseGitPackage(githubApi, settingsManager, downloadService, prerequisiteHelper, pyInstallationManager)
2426
{
2527
private AnsiProcess? npmProcess;
28+
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
2629

2730
public override string Name => "ai-toolkit";
2831
public override string DisplayName { get; set; } = "AI-Toolkit";
@@ -186,12 +189,11 @@ await npmProcess
186189
}
187190
catch (OperationCanceledException e)
188191
{
189-
Console.WriteLine(e);
192+
Logger.Warn(e, "Timed out waiting for npm to exit");
193+
npmProcess.CancelStreamReaders();
190194
}
191195
}
192-
193196
npmProcess = null;
194-
GC.SuppressFinalize(this);
195197
}
196198

197199
private ImmutableDictionary<string, string> GetEnvVars(ImmutableDictionary<string, string> env)

StabilityMatrix.Core/Models/Packages/Extensions/GitPackageExtensionManager.cs

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using KGySoft.CoreLibraries;
33
using Microsoft.Extensions.Caching.Memory;
44
using NLog;
5+
using StabilityMatrix.Core.Exceptions;
56
using StabilityMatrix.Core.Extensions;
67
using StabilityMatrix.Core.Helper;
78
using StabilityMatrix.Core.Models.FileInterfaces;
@@ -80,9 +81,10 @@ public virtual async Task<IEnumerable<InstalledPackageExtension>> GetInstalledEx
8081

8182
// Search for installed extensions in the package's index directories.
8283
foreach (
83-
var indexDirectory in IndexRelativeDirectories.Select(
84-
path => new DirectoryPath(packagePath, path)
85-
)
84+
var indexDirectory in IndexRelativeDirectories.Select(path => new DirectoryPath(
85+
packagePath,
86+
path
87+
))
8688
)
8789
{
8890
cancellationToken.ThrowIfCancellationRequested();
@@ -120,11 +122,11 @@ var indexDirectory in IndexRelativeDirectories.Select(
120122
{
121123
Tag = version.Tag,
122124
Branch = version.Branch,
123-
CommitSha = version.CommitSha
125+
CommitSha = version.CommitSha,
124126
},
125127
GitRepositoryUrl = remoteUrlResult.IsSuccessExitCode
126128
? remoteUrlResult.StandardOutput?.Trim()
127-
: null
129+
: null,
128130
}
129131
);
130132
}
@@ -150,9 +152,10 @@ public virtual async Task<IEnumerable<InstalledPackageExtension>> GetInstalledEx
150152

151153
// Search for installed extensions in the package's index directories.
152154
foreach (
153-
var indexDirectory in IndexRelativeDirectories.Select(
154-
path => new DirectoryPath(packagePath, path)
155-
)
155+
var indexDirectory in IndexRelativeDirectories.Select(path => new DirectoryPath(
156+
packagePath,
157+
path
158+
))
156159
)
157160
{
158161
cancellationToken.ThrowIfCancellationRequested();
@@ -221,8 +224,8 @@ InstalledPackageExtension installedExtension
221224
{
222225
Tag = version.Tag,
223226
Branch = version.Branch,
224-
CommitSha = version.CommitSha
225-
}
227+
CommitSha = version.CommitSha,
228+
},
226229
};
227230
}
228231

@@ -257,14 +260,34 @@ public virtual async Task InstallExtensionAsync(
257260
new ProgressReport(0f, message: $"Cloning {repositoryUri}", isIndeterminate: true)
258261
);
259262

260-
await prerequisiteHelper
261-
.CloneGitRepository(
262-
cloneRoot,
263-
repositoryUri.ToString(),
264-
version,
265-
progress.AsProcessOutputHandler()
266-
)
267-
.ConfigureAwait(false);
263+
try
264+
{
265+
await prerequisiteHelper
266+
.CloneGitRepository(
267+
cloneRoot,
268+
repositoryUri.ToString(),
269+
version,
270+
progress.AsProcessOutputHandler()
271+
)
272+
.ConfigureAwait(false);
273+
}
274+
catch (ProcessException ex)
275+
{
276+
if (ex.Message.Contains("Git exited with code 128"))
277+
{
278+
progress?.Report(
279+
new ProgressReport(
280+
-1f,
281+
$"Unable to check out commit {version?.CommitSha} - continuing with latest commit from {version?.Branch}\n\n{ex.ProcessResult?.StandardError}\n",
282+
isIndeterminate: true
283+
)
284+
);
285+
}
286+
else
287+
{
288+
throw;
289+
}
290+
}
268291

269292
progress?.Report(new ProgressReport(1f, message: $"Cloned {repositoryUri}"));
270293
}

0 commit comments

Comments
 (0)