Skip to content

Commit

Permalink
Wrapped some work in try/catch blocks so the updater doesn't crash ha…
Browse files Browse the repository at this point in the history
…lf-way through the process. At a minimum, it will give better error logging for crashes now
  • Loading branch information
ProgrammerAL committed Oct 5, 2024
1 parent 738ebf8 commit 71c23a4
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 5 deletions.
31 changes: 29 additions & 2 deletions src/CodeUpdater/CodeUpdater/Updaters/CSharpUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ public async ValueTask<ImmutableArray<CSharpUpdateResult>> UpdateAllCSharpProjec
{
_logger.Information($"Updating '{csProjFilePath}'");

var nugetUpdates = await _nugetUpdater.UpdateNugetPackagesAsync(csProjFilePath);
var csProjUpdates = _csProjUpdater.UpdateCsProjPropertyValues(csProjFilePath);

var nugetUpdates = await UpdateNugetPackagesAsync(csProjFilePath);
var csProjUpdates = UpdateCsProjPropertyValues(csProjFilePath);

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

return builder.ToImmutableArray();
}

private async ValueTask<NugetUpdateResults> UpdateNugetPackagesAsync(string csProjFilePath)
{
try
{
return await _nugetUpdater.UpdateNugetPackagesAsync(csProjFilePath);
}
catch (Exception ex)
{
_logger.Error("Error updating nuget packages in csproj file '{CsProjFilePath}'. {Ex}", csProjFilePath, ex.ToString());
return new NugetUpdateResults(RetrievedPackageListSuccessfully: false, ImmutableArray<NugetUpdateResult>.Empty);
}
}

private CsProjUpdateResult UpdateCsProjPropertyValues(string csProjFilePath)
{
try
{
return _csProjUpdater.UpdateCsProjPropertyValues(csProjFilePath);
}
catch (Exception ex)
{
_logger.Error("Error updating csproj file '{CsProjFilePath}'. {Ex}", csProjFilePath, ex.ToString());
return new CsProjUpdateResult(csProjFilePath, CsprojValueUpdateResultType.Unknown, CsprojValueUpdateResultType.Unknown);
}
}
}
20 changes: 17 additions & 3 deletions src/CodeUpdater/CodeUpdater/Updaters/NpmUpdater.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.Tracing;
using System.IO;
using System.Linq;
using System.Text;
Expand All @@ -18,9 +19,22 @@ public NpmUpdates UpdateNpmPackages(UpdateWork updateWork)
{
foreach (var projectPath in updateWork.NpmDirectories)
{
RunProcessHelper.RunProwerShellCommandToCompletion(projectPath, "npm-check-updates --upgrade");
RunProcessHelper.RunProwerShellCommandToCompletion(projectPath, "npm install --legacy-peer-deps");
RunProcessHelper.RunProwerShellCommandToCompletion(projectPath, "npm audit fix --force");
string command = "";
try
{
command = "npm-check-updates --upgrade";
RunProcessHelper.RunProwerShellCommandToCompletion(projectPath, command);

command = "npm install --legacy-peer-deps";
RunProcessHelper.RunProwerShellCommandToCompletion(projectPath, command);

command = "npm audit fix --force";
RunProcessHelper.RunProwerShellCommandToCompletion(projectPath, command);
}
catch (Exception ex)
{
Log.Error(ex, "Error updating npm packages at path'{ProjectPath}'. Command was '{Command}'", projectPath, command);
}
}

return new NpmUpdates(updateWork.NpmDirectories);
Expand Down

0 comments on commit 71c23a4

Please sign in to comment.