Skip to content

Commit

Permalink
implemented more error handling
Browse files Browse the repository at this point in the history
implemented more error handling, especially for async methods
  • Loading branch information
HotCakeX committed Jul 27, 2024
1 parent 3b4ed38 commit 1d1abdb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ public static void PrepDownloadedFiles(bool GUI = false, string LGPOPath = null,

if (DownloadsTask.IsFaulted)
{
throw new Exception(DownloadsTask.Exception.Message);
// throw the exceptions
throw DownloadsTask.Exception;
}
else if (DownloadsTask.IsCompletedSuccessfully)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,14 @@ public static void OrchestrateComplianceChecks(params string[] methodNames)
if (MethodsTaskOutput.IsFaulted)
{
// throw the exceptions
throw new Exception(MethodsTaskOutput.Exception.Message);
throw MethodsTaskOutput.Exception;

// this should automatically throw ?
// MethodsTaskOutput.GetAwaiter().GetResult()
}
else if (MethodsTaskOutput.IsCompletedSuccessfully)
{
// Console.WriteLine("Download completed successfully");
// Console.WriteLine("Download completed successfully");
}
}

Expand Down
13 changes: 10 additions & 3 deletions Harden-Windows-Security Module/Main files/C#/WriteVerbose.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,17 @@ public static class VerboseLogger
/// <param name="message"></param>
public static void Write(string message)
{
if (HardeningModule.GlobalVars.VerbosePreference == "Continue" || HardeningModule.GlobalVars.VerbosePreference == "Inquire")
try
{
HardeningModule.GlobalVars.Host.UI.WriteVerboseLine(message);
if (HardeningModule.GlobalVars.VerbosePreference == "Continue" || HardeningModule.GlobalVars.VerbosePreference == "Inquire")
{
HardeningModule.GlobalVars.Host.UI.WriteVerboseLine(message);
}
}
// Do not do anything if errors occur
// Since many methods write to the console asynchronously this can throw errors
// implement better ways such as using log file or in the near future a GUI for writing verbose messages when -Verbose is used
catch { }
}
}
}
}

0 comments on commit 1d1abdb

Please sign in to comment.