Refactor exception handling to remove specific exception types in multiple helper classes
This commit is contained in:
@ -1145,7 +1145,7 @@ internal static partial class Helper20240105
|
||||
#pragma warning restore IL2026
|
||||
stream.Dispose();
|
||||
}
|
||||
catch (Exception)
|
||||
catch
|
||||
{
|
||||
if (throwExceptions)
|
||||
throw;
|
||||
|
||||
@ -230,7 +230,7 @@ internal static partial class Helper20240623 {
|
||||
{
|
||||
"label": "File-Folder-Helper AOT s X Day-Helper-2024-06-23",
|
||||
"type": "shell",
|
||||
"command": "L:/DevOps/Mesa_FI/File-Folder-Helper/bin/Release/net8.0/win-x64/publish/File-Folder-Helper.exe",
|
||||
"command": "L:/DevOps/Mesa_FI/File-Folder-Helper/bin/Release/net10.0/win-x64/publish/File-Folder-Helper.exe",
|
||||
"args": [
|
||||
"s",
|
||||
"X",
|
||||
@ -573,7 +573,7 @@ internal static partial class Helper20240623 {
|
||||
File.WriteAllText(record.FileInfo.FullName, text);
|
||||
record.FileInfo.Refresh();
|
||||
string file = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Programs", "Microsoft VS Code Insiders", "Code - Insiders.exe");
|
||||
try { _ = Process.Start(file, $"\"{inferredCheckDirectory}\""); } catch (Exception) { logger.LogWarning("Failed to start code-insiders!"); }
|
||||
try { _ = Process.Start(file, $"\"{inferredCheckDirectory}\""); } catch { logger.LogWarning("Failed to start code-insiders!"); }
|
||||
}
|
||||
|
||||
private static FileInfo GetIndexFileInfo(ILogger<Worker> logger, Input input, Record record) {
|
||||
|
||||
@ -283,7 +283,7 @@ internal static partial class Helper20240911
|
||||
records = GetKeyValuePairs(keyValuePairs, keyValuePair.Value, nests);
|
||||
record = new(keyValuePair.Value, parentWorkItem, records);
|
||||
}
|
||||
catch (Exception)
|
||||
catch
|
||||
{
|
||||
record = new(keyValuePair.Value, parentWorkItem, new([]));
|
||||
}
|
||||
|
||||
@ -274,7 +274,7 @@ internal static partial class Helper20241108 {
|
||||
relatedRecords = Record.GetKeyValuePairs(keyValuePairs, keyValuePair.Value, "Related", nests, keepRelations); // Related
|
||||
successorRecords = Record.GetKeyValuePairs(keyValuePairs, keyValuePair.Value, "Successor", nests, keepRelations); // Forward
|
||||
record = Record.Get(keyValuePair.Value, parentWorkItem, childRecords, relatedRecords, successorRecords, keepRelations);
|
||||
} catch (Exception) {
|
||||
} catch {
|
||||
record = new(keyValuePair.Value, parentWorkItem, [], [], []);
|
||||
}
|
||||
results.Add(keyValuePair.Key, record);
|
||||
|
||||
@ -79,7 +79,7 @@ internal static partial class Helper20250204 {
|
||||
"{",
|
||||
"\"label\": \"File-Folder-Helper AOT s X Day-Helper-2025-02-04\",",
|
||||
"\"type\": \"shell\",",
|
||||
"\"command\": \"L:/DevOps/Mesa_FI/File-Folder-Helper/bin/Release/net8.0/win-x64/publish/File-Folder-Helper.exe\",",
|
||||
"\"command\": \"L:/DevOps/Mesa_FI/File-Folder-Helper/bin/Release/net10.0/win-x64/publish/File-Folder-Helper.exe\",",
|
||||
"\"args\": [",
|
||||
"\"s\",",
|
||||
"\"X\",",
|
||||
@ -92,7 +92,7 @@ internal static partial class Helper20250204 {
|
||||
"{",
|
||||
"\"label\": \"File-Folder-Helper AOT s X Day-Helper-2024-06-23\",",
|
||||
"\"type\": \"shell\",",
|
||||
"\"command\": \"L:/DevOps/Mesa_FI/File-Folder-Helper/bin/Release/net8.0/win-x64/publish/File-Folder-Helper.exe\",",
|
||||
"\"command\": \"L:/DevOps/Mesa_FI/File-Folder-Helper/bin/Release/net10.0/win-x64/publish/File-Folder-Helper.exe\",",
|
||||
"\"args\": [",
|
||||
"\"s\",",
|
||||
"\"X\",",
|
||||
|
||||
@ -15,7 +15,7 @@ internal static partial class Helper20250219 {
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||
[JsonSerializable(typeof(JsonElement[]))]
|
||||
private partial class JsonElementCollectionSourceGenerationContext : JsonSerializerContext {
|
||||
private partial class Helper20250219JsonElementArraySourceGenerationContext : JsonSerializerContext {
|
||||
}
|
||||
|
||||
private record ProcessDataStandardFormatMapping(ReadOnlyCollection<string> BackfillColumns,
|
||||
@ -276,7 +276,7 @@ internal static partial class Helper20250219 {
|
||||
private static JsonElement[]? GetArray(ILogger<Worker> logger, int expectedColumns, ProcessDataStandardFormat processDataStandardFormat, bool lookForNumbers) {
|
||||
JsonElement[]? results;
|
||||
if (processDataStandardFormat.Body.Count == 0 || !processDataStandardFormat.Body[0].Contains('\t')) {
|
||||
results = JsonSerializer.Deserialize("[]", JsonElementCollectionSourceGenerationContext.Default.JsonElementArray) ?? throw new Exception();
|
||||
results = JsonSerializer.Deserialize("[]", Helper20250219JsonElementArraySourceGenerationContext.Default.JsonElementArray) ?? throw new Exception();
|
||||
} else {
|
||||
string value;
|
||||
string[] segments;
|
||||
@ -312,7 +312,7 @@ internal static partial class Helper20250219 {
|
||||
lines.Add(stringBuilder.ToString());
|
||||
}
|
||||
string json = $"[{string.Join(',', lines)}]";
|
||||
results = JsonSerializer.Deserialize(json, JsonElementCollectionSourceGenerationContext.Default.JsonElementArray);
|
||||
results = JsonSerializer.Deserialize(json, Helper20250219JsonElementArraySourceGenerationContext.Default.JsonElementArray);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
@ -315,7 +315,7 @@ internal static partial class Helper20250320 {
|
||||
segments = value.Split(' ');
|
||||
results.Add(segments[^1], value);
|
||||
}
|
||||
} catch (Exception) {
|
||||
} catch {
|
||||
results.Clear();
|
||||
System.Text.RegularExpressions.Match m;
|
||||
for (int i = 0; i < matches.Length; i++) {
|
||||
|
||||
@ -552,7 +552,7 @@ internal static partial class Helper20250407 {
|
||||
private static void DoWork(ILogger<Worker> logger, string rightDirectory, HttpClient httpClient, ReadOnlyCollection<Segment> segments, bool delete, bool download) {
|
||||
long sum;
|
||||
Record[] records = (from l in segments where l.Left is not null select l.Left).ToArray();
|
||||
try { sum = records.Sum(l => l.Size); } catch (Exception) { sum = 0; }
|
||||
try { sum = records.Sum(l => l.Size); } catch { sum = 0; }
|
||||
string size = GetSizeWithSuffix(sum);
|
||||
if (delete) {
|
||||
logger.LogInformation("Starting to delete {count} file(s) [{sum}]", segments.Count, size);
|
||||
@ -601,7 +601,7 @@ internal static partial class Helper20250407 {
|
||||
try {
|
||||
File.Delete(Path.Combine(rightDirectory, record.RelativePath));
|
||||
logger.LogInformation("{i} of {count} - Deleted: <{RelativePath}> - {size};", i.ToString("000000"), count, record.RelativePath, size);
|
||||
} catch (Exception) {
|
||||
} catch {
|
||||
logger.LogInformation("Failed to delete: <{RelativePath}> - {size};", record.RelativePath, size);
|
||||
}
|
||||
}
|
||||
@ -648,7 +648,7 @@ internal static partial class Helper20250407 {
|
||||
download.Display,
|
||||
size,
|
||||
duration);
|
||||
} catch (Exception) {
|
||||
} catch {
|
||||
logger.LogInformation("Failed to download: <{checkURL}> - {size};", download.UniformResourceLocator, size);
|
||||
}
|
||||
}
|
||||
|
||||
@ -439,7 +439,7 @@ internal static partial class Helper20250519 {
|
||||
try {
|
||||
File.Delete(Path.Combine(directory, record.RelativePath));
|
||||
logger.LogInformation("{i} of {count} - Deleted: <{RelativePath}> - {size};", i.ToString("000000"), count, record.RelativePath, size);
|
||||
} catch (Exception) {
|
||||
} catch {
|
||||
logger.LogInformation("Failed to delete: <{RelativePath}> - {size};", record.RelativePath, size);
|
||||
}
|
||||
}
|
||||
@ -507,7 +507,7 @@ internal static partial class Helper20250519 {
|
||||
verb.Display,
|
||||
size,
|
||||
duration);
|
||||
} catch (Exception) {
|
||||
} catch {
|
||||
logger.LogInformation("Failed to {httpMethod}: <{display}> - {size};", httpMethod, verb.Display, size);
|
||||
}
|
||||
}
|
||||
@ -519,7 +519,7 @@ internal static partial class Helper20250519 {
|
||||
|
||||
private static void LiveSync(ILogger<Worker> logger, string page, RelativePath relativePath, HttpClient httpClient, string? directory, ReadOnlyCollection<Record> records, HttpMethod? httpMethod, bool delete) {
|
||||
long sum;
|
||||
try { sum = records.Sum(l => l.Size); } catch (Exception) { sum = 0; }
|
||||
try { sum = records.Sum(l => l.Size); } catch { sum = 0; }
|
||||
string size = GetSizeWithSuffix(sum);
|
||||
if (delete) {
|
||||
logger.LogInformation("Starting to delete {count} file(s) [{sum}]", records.Count, size);
|
||||
|
||||
@ -41,7 +41,7 @@ internal static partial class Helper20250601 {
|
||||
result = xmlSerializer.Deserialize(xmlReader);
|
||||
#pragma warning restore IL2026, IL2090
|
||||
stream.Dispose();
|
||||
} catch (Exception) {
|
||||
} catch {
|
||||
if (throwExceptions) {
|
||||
throw;
|
||||
}
|
||||
|
||||
@ -39,7 +39,7 @@ internal static partial class Helper20250602 {
|
||||
result = xmlSerializer.Deserialize(xmlReader);
|
||||
#pragma warning restore IL2026, IL2090
|
||||
stream.Dispose();
|
||||
} catch (Exception) {
|
||||
} catch {
|
||||
if (throwExceptions) {
|
||||
throw;
|
||||
}
|
||||
|
||||
@ -10,7 +10,7 @@ internal static partial class Helper20250701 {
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)]
|
||||
[JsonSerializable(typeof(JsonElement))]
|
||||
internal partial class JsonElementSourceGenerationContext : JsonSerializerContext {
|
||||
internal partial class Helper20250701JsonElementSourceGenerationContext : JsonSerializerContext {
|
||||
}
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)]
|
||||
@ -403,7 +403,7 @@ internal static partial class Helper20250701 {
|
||||
List<string> values = [];
|
||||
List<string> results = [];
|
||||
Dictionary<string, string> keyValuePairs = [];
|
||||
JsonElement jsonElement = JsonSerializer.Deserialize(json, JsonElementSourceGenerationContext.Default.JsonElement);
|
||||
JsonElement jsonElement = JsonSerializer.Deserialize(json, Helper20250701JsonElementSourceGenerationContext.Default.JsonElement);
|
||||
JsonElement[] jsonElements = jsonElement.EnumerateArray().ToArray();
|
||||
foreach (JsonElement j in jsonElements) {
|
||||
values.Clear();
|
||||
|
||||
@ -199,7 +199,7 @@ internal static partial class Helper20250709 {
|
||||
foreach (JsonElement jsonElement in raw.Records) {
|
||||
try {
|
||||
reactor = JsonSerializer.Deserialize(jsonElement.ToString().Replace("\"\"", "null"), ReactorSourceGenerationContext.Default.Reactor);
|
||||
} catch (Exception) {
|
||||
} catch {
|
||||
reactor = null;
|
||||
}
|
||||
if (reactor is null) {
|
||||
|
||||
@ -146,7 +146,7 @@ internal static partial class Helper20251113 {
|
||||
result = xmlSerializer.Deserialize(xmlReader);
|
||||
#pragma warning restore IL2026, IL2090
|
||||
stream.Dispose();
|
||||
} catch (Exception) {
|
||||
} catch {
|
||||
result = null;
|
||||
if (throwExceptions) {
|
||||
throw;
|
||||
|
||||
@ -111,7 +111,7 @@ internal static partial class Helper20231024
|
||||
File.WriteAllText($"{drive.Share}\\Tmp\\Phares\\MESA-Users-Drives.bat", bat);
|
||||
File.WriteAllText($"{drive.Share}\\Tmp\\Phares\\lnk.txt", """"\\messa04ec.infineon.com\EC_SPC_Si\SPC\Projects\Active\ir epi services database.ipj"""");
|
||||
}
|
||||
catch (Exception)
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
}
|
||||
|
||||
@ -115,7 +115,7 @@ internal static class HelperDeleteEmptyDirectories
|
||||
logger.LogInformation("{directoryName}", Path.GetFileName(directory5));
|
||||
Directory.Delete(directory5, recursive: true);
|
||||
}
|
||||
catch (Exception)
|
||||
catch
|
||||
{ errorHappened = true; }
|
||||
}
|
||||
if (!errorHappened)
|
||||
@ -125,7 +125,7 @@ internal static class HelperDeleteEmptyDirectories
|
||||
logger.LogInformation("{directoryName}", Path.GetFileName(directory4));
|
||||
Directory.Delete(directory4, recursive: true);
|
||||
}
|
||||
catch (Exception)
|
||||
catch
|
||||
{ errorHappened = true; }
|
||||
}
|
||||
}
|
||||
@ -136,7 +136,7 @@ internal static class HelperDeleteEmptyDirectories
|
||||
logger.LogInformation("{directoryName}", Path.GetFileName(directory3));
|
||||
Directory.Delete(directory3, recursive: true);
|
||||
}
|
||||
catch (Exception)
|
||||
catch
|
||||
{ errorHappened = true; }
|
||||
}
|
||||
}
|
||||
@ -147,7 +147,7 @@ internal static class HelperDeleteEmptyDirectories
|
||||
logger.LogInformation("{directoryName}", Path.GetFileName(directory2));
|
||||
Directory.Delete(directory2, recursive: true);
|
||||
}
|
||||
catch (Exception)
|
||||
catch
|
||||
{ errorHappened = true; }
|
||||
}
|
||||
}
|
||||
@ -158,7 +158,7 @@ internal static class HelperDeleteEmptyDirectories
|
||||
logger.LogInformation("{directoryName}", Path.GetFileName(directory1));
|
||||
Directory.Delete(directory1, recursive: true);
|
||||
}
|
||||
catch (Exception)
|
||||
catch
|
||||
{ errorHappened = true; }
|
||||
}
|
||||
}
|
||||
@ -169,7 +169,7 @@ internal static class HelperDeleteEmptyDirectories
|
||||
logger.LogInformation("{directoryName}", Path.GetFileName(rootDirectory));
|
||||
Directory.Delete(rootDirectory, recursive: true);
|
||||
}
|
||||
catch (Exception)
|
||||
catch
|
||||
{ errorHappened = true; }
|
||||
}
|
||||
if (!errorHappened)
|
||||
|
||||
@ -40,7 +40,7 @@ internal static class HelperRenameToOldMoveDeleteOldMerge
|
||||
File.Delete(deleteFile);
|
||||
break;
|
||||
}
|
||||
catch (Exception) { }
|
||||
catch { }
|
||||
Thread.Sleep(500);
|
||||
}
|
||||
}
|
||||
|
||||
@ -102,7 +102,7 @@ internal static partial class HelperZipFilesBy
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
catch
|
||||
{
|
||||
logger.LogInformation("<{zipFile}> is invalid!", zipFile);
|
||||
checkFile = string.Concat(zipFile, ".err");
|
||||
@ -114,7 +114,7 @@ internal static partial class HelperZipFilesBy
|
||||
}
|
||||
try
|
||||
{ File.Move(zipFile, checkFile); }
|
||||
catch (Exception) { logger.LogInformation("<{zipFile}> couldn't be moved!", zipFile); }
|
||||
catch { logger.LogInformation("<{zipFile}> couldn't be moved!", zipFile); }
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@ -142,7 +142,7 @@ internal static partial class HelperZipFilesBy
|
||||
}
|
||||
break;
|
||||
}
|
||||
catch (Exception)
|
||||
catch
|
||||
{
|
||||
File.Delete(zipFile);
|
||||
zipArchiveMode = ZipArchiveMode.Create;
|
||||
@ -265,7 +265,7 @@ internal static partial class HelperZipFilesBy
|
||||
if (zipPath is not null && Directory.Exists(zipPath) && !string.IsNullOrEmpty(directoryName))
|
||||
try
|
||||
{ Directory.SetLastWriteTime(directoryName, DateTime.Now); }
|
||||
catch (Exception) { }
|
||||
catch { }
|
||||
}
|
||||
subFiles = Directory.GetFiles(zipDirectory, "*.zip", SearchOption.TopDirectoryOnly);
|
||||
foreach (string subFile in subFiles)
|
||||
@ -281,12 +281,12 @@ internal static partial class HelperZipFilesBy
|
||||
result = true;
|
||||
File.SetLastWriteTime(subFile, value);
|
||||
}
|
||||
catch (Exception) { }
|
||||
catch { }
|
||||
}
|
||||
if (topDirectory != sourceDirectory)
|
||||
try
|
||||
{ HelperDeleteEmptyDirectories.DeleteEmptyDirectories(logger, topDirectory); }
|
||||
catch (Exception) { }
|
||||
catch { }
|
||||
logger.LogInformation("{topDirectory}", topDirectory);
|
||||
}
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user