Skip to content

Commit

Permalink
chore: Added aditional error handling for mod update background checker
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorixon committed Jan 28, 2024
1 parent a940dc7 commit 74f3cc7
Showing 1 changed file with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,35 @@ public Task InitializeAsync()
var stoppingToken = _stoppingCancellationTokenSource.Token;


Task.Factory.StartNew(() => StartBackgroundChecker(stoppingToken), stoppingToken,
Task.Factory.StartNew(
() => CatchAll(() => StartBackgroundChecker(stoppingToken), nameof(StartBackgroundChecker)), stoppingToken,
TaskCreationOptions.LongRunning, TaskScheduler.Default);

Task.Factory.StartNew(() => AutoCheckerProducer(stoppingToken), stoppingToken, TaskCreationOptions.LongRunning,
Task.Factory.StartNew(() => CatchAll(() => AutoCheckerProducer(stoppingToken), nameof(AutoCheckerProducer)),
stoppingToken,
TaskCreationOptions.LongRunning,
TaskScheduler.Default);

return Task.CompletedTask;
}

private async Task CatchAll(Func<Task> func, string methodName)
{
try
{
await func();
}
catch (Exception e)
{
_logger.Error(e, "An error occurred while executing {FuncName}", methodName);
_notificationManager.ShowNotification(
$"An error occurred in the mod update background checker",
$"A fatal error occured in the background checker ({methodName} : {e.HResult}). This means that JASM can no longer check for mod updates in the background or manually. Error: {e}",
TimeSpan.FromSeconds(20));
Status = RunningState.Error;
}
}


private async Task StartBackgroundChecker(CancellationToken stoppingToken)
{
Expand Down

0 comments on commit 74f3cc7

Please sign in to comment.