Skip to content

Commit 71c23a4

Browse files
committed
Wrapped some work in try/catch blocks so the updater doesn't crash half-way through the process. At a minimum, it will give better error logging for crashes now
1 parent 738ebf8 commit 71c23a4

File tree

2 files changed

+46
-5
lines changed

2 files changed

+46
-5
lines changed

src/CodeUpdater/CodeUpdater/Updaters/CSharpUpdater.cs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ public async ValueTask<ImmutableArray<CSharpUpdateResult>> UpdateAllCSharpProjec
3838
{
3939
_logger.Information($"Updating '{csProjFilePath}'");
4040

41-
var nugetUpdates = await _nugetUpdater.UpdateNugetPackagesAsync(csProjFilePath);
42-
var csProjUpdates = _csProjUpdater.UpdateCsProjPropertyValues(csProjFilePath);
41+
42+
var nugetUpdates = await UpdateNugetPackagesAsync(csProjFilePath);
43+
var csProjUpdates = UpdateCsProjPropertyValues(csProjFilePath);
4344

4445
builder.Add(new CSharpUpdateResult(
4546
csProjFilePath,
@@ -50,4 +51,30 @@ public async ValueTask<ImmutableArray<CSharpUpdateResult>> UpdateAllCSharpProjec
5051

5152
return builder.ToImmutableArray();
5253
}
54+
55+
private async ValueTask<NugetUpdateResults> UpdateNugetPackagesAsync(string csProjFilePath)
56+
{
57+
try
58+
{
59+
return await _nugetUpdater.UpdateNugetPackagesAsync(csProjFilePath);
60+
}
61+
catch (Exception ex)
62+
{
63+
_logger.Error("Error updating nuget packages in csproj file '{CsProjFilePath}'. {Ex}", csProjFilePath, ex.ToString());
64+
return new NugetUpdateResults(RetrievedPackageListSuccessfully: false, ImmutableArray<NugetUpdateResult>.Empty);
65+
}
66+
}
67+
68+
private CsProjUpdateResult UpdateCsProjPropertyValues(string csProjFilePath)
69+
{
70+
try
71+
{
72+
return _csProjUpdater.UpdateCsProjPropertyValues(csProjFilePath);
73+
}
74+
catch (Exception ex)
75+
{
76+
_logger.Error("Error updating csproj file '{CsProjFilePath}'. {Ex}", csProjFilePath, ex.ToString());
77+
return new CsProjUpdateResult(csProjFilePath, CsprojValueUpdateResultType.Unknown, CsprojValueUpdateResultType.Unknown);
78+
}
79+
}
5380
}

src/CodeUpdater/CodeUpdater/Updaters/NpmUpdater.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Diagnostics;
4+
using System.Diagnostics.Tracing;
45
using System.IO;
56
using System.Linq;
67
using System.Text;
@@ -18,9 +19,22 @@ public NpmUpdates UpdateNpmPackages(UpdateWork updateWork)
1819
{
1920
foreach (var projectPath in updateWork.NpmDirectories)
2021
{
21-
RunProcessHelper.RunProwerShellCommandToCompletion(projectPath, "npm-check-updates --upgrade");
22-
RunProcessHelper.RunProwerShellCommandToCompletion(projectPath, "npm install --legacy-peer-deps");
23-
RunProcessHelper.RunProwerShellCommandToCompletion(projectPath, "npm audit fix --force");
22+
string command = "";
23+
try
24+
{
25+
command = "npm-check-updates --upgrade";
26+
RunProcessHelper.RunProwerShellCommandToCompletion(projectPath, command);
27+
28+
command = "npm install --legacy-peer-deps";
29+
RunProcessHelper.RunProwerShellCommandToCompletion(projectPath, command);
30+
31+
command = "npm audit fix --force";
32+
RunProcessHelper.RunProwerShellCommandToCompletion(projectPath, command);
33+
}
34+
catch (Exception ex)
35+
{
36+
Log.Error(ex, "Error updating npm packages at path'{ProjectPath}'. Command was '{Command}'", projectPath, command);
37+
}
2438
}
2539

2640
return new NpmUpdates(updateWork.NpmDirectories);

0 commit comments

Comments
 (0)