From 04b0805703ae972788fc0720c285f620a4977ee2 Mon Sep 17 00:00:00 2001 From: maj00r Date: Mon, 31 Aug 2026 00:44:42 +0200 Subject: [PATCH] log swallowed exceptions and missing translation keys --- StarterNG/Classes/KeyboardConfig.cs | 4 ++-- StarterNG/Classes/Physics.cs | 7 +++++-- StarterNG/Classes/PresetStore.cs | 8 ++++---- StarterNG/Classes/Settings.cs | 9 +++++--- StarterNG/Domain/SceneryI18n.cs | 5 ++++- StarterNG/Infrastructure/MonoFont.cs | 4 +++- StarterNG/MainWindow.axaml.cs | 4 +++- StarterNG/Services/LocalizationService.cs | 24 ++++++++++++++++++---- StarterNG/Views/Scenarios.axaml.cs | 5 ++++- StarterNG/Views/TextureBaseWindow.axaml.cs | 1 - 10 files changed, 51 insertions(+), 20 deletions(-) diff --git a/StarterNG/Classes/KeyboardConfig.cs b/StarterNG/Classes/KeyboardConfig.cs index 5a3e689..b3fd6cd 100644 --- a/StarterNG/Classes/KeyboardConfig.cs +++ b/StarterNG/Classes/KeyboardConfig.cs @@ -215,9 +215,9 @@ public sealed class KeyboardConfig File.WriteAllText(_savePath, ToText(), FileEncoding); Dirty = false; } - catch + catch (Exception ex) { - + StarterNG.Infrastructure.Diagnostics.Log($"saving {_savePath}", ex); } } } diff --git a/StarterNG/Classes/Physics.cs b/StarterNG/Classes/Physics.cs index 4b45078..d81ac96 100644 --- a/StarterNG/Classes/Physics.cs +++ b/StarterNG/Classes/Physics.cs @@ -38,7 +38,10 @@ public sealed class Physics foreach (string f in Directory.EnumerateFiles(dynamicRoot, "*.fiz", SearchOption.AllDirectories)) index[Path.GetFileNameWithoutExtension(f)] = f; } - catch { } + catch (Exception ex) + { + StarterNG.Infrastructure.Diagnostics.Log($"indexing {dynamicRoot}", ex); + } _fizIndex = index; return index; @@ -66,7 +69,7 @@ public sealed class Physics { phys = new Physics { AllowedFlagB = -1 }; try { Parse(phys, path, Path.GetDirectoryName(path) ?? "", null, 0); } - catch { } + catch (Exception ex) { StarterNG.Infrastructure.Diagnostics.Log($"physics/{Path.GetFileName(path)}", ex); } if (phys.AllowedFlagB == -1) { diff --git a/StarterNG/Classes/PresetStore.cs b/StarterNG/Classes/PresetStore.cs index bd62d0f..c024e57 100644 --- a/StarterNG/Classes/PresetStore.cs +++ b/StarterNG/Classes/PresetStore.cs @@ -173,9 +173,9 @@ public static class PresetStore return col; } } - catch + catch (Exception ex) { - + StarterNG.Infrastructure.Diagnostics.Log($"reading {FilePath}", ex); } return new PresetCollection(); } @@ -187,9 +187,9 @@ public static class PresetStore Directory.CreateDirectory(Path.GetDirectoryName(FilePath)!); File.WriteAllText(FilePath, JsonSerializer.Serialize(col, TypeInfo)); } - catch + catch (Exception ex) { - + StarterNG.Infrastructure.Diagnostics.Log($"saving {FilePath}", ex); } } } diff --git a/StarterNG/Classes/Settings.cs b/StarterNG/Classes/Settings.cs index 9e97875..ff86e8f 100644 --- a/StarterNG/Classes/Settings.cs +++ b/StarterNG/Classes/Settings.cs @@ -198,7 +198,10 @@ public sealed class Settings fallback ??= path; } } - catch { } + catch (Exception ex) + { + StarterNG.Infrastructure.Diagnostics.Log("looking for the simulator executable", ex); + } if (fallback != null) { @@ -346,9 +349,9 @@ public sealed class Settings File.WriteAllText(path, _config.ToText(), FileEncoding); TouchConfigAge(); } - catch + catch (Exception ex) { - + StarterNG.Infrastructure.Diagnostics.Log($"saving {path}", ex); } } diff --git a/StarterNG/Domain/SceneryI18n.cs b/StarterNG/Domain/SceneryI18n.cs index f1e9aa4..dd6e001 100644 --- a/StarterNG/Domain/SceneryI18n.cs +++ b/StarterNG/Domain/SceneryI18n.cs @@ -44,7 +44,10 @@ public static class SceneryI18n if (doc.RootElement.ValueKind == JsonValueKind.Object) Flatten("", doc.RootElement); } - catch { } + catch (Exception ex) + { + StarterNG.Infrastructure.Diagnostics.Log($"scenery i18n/{Path.GetFileName(path)}", ex); + } } private static void Flatten(string prefix, JsonElement obj) diff --git a/StarterNG/Infrastructure/MonoFont.cs b/StarterNG/Infrastructure/MonoFont.cs index 2cd43f4..a3dfdda 100644 --- a/StarterNG/Infrastructure/MonoFont.cs +++ b/StarterNG/Infrastructure/MonoFont.cs @@ -38,7 +38,9 @@ public static class MonoFont if (anyMono is not null) return new FontFamily(anyMono); } - catch { } + catch + { + } return FontFamily.Default; } diff --git a/StarterNG/MainWindow.axaml.cs b/StarterNG/MainWindow.axaml.cs index f2496fd..5de412c 100644 --- a/StarterNG/MainWindow.axaml.cs +++ b/StarterNG/MainWindow.axaml.cs @@ -446,7 +446,9 @@ public partial class MainWindow : Window var watcher = new Thread(() => { try { sim.WaitForExit(); } - catch { } + catch + { + } Dispatcher.UIThread.Post(RestoreFromSimulator); }) { diff --git a/StarterNG/Services/LocalizationService.cs b/StarterNG/Services/LocalizationService.cs index a41924e..6acaa8c 100644 --- a/StarterNG/Services/LocalizationService.cs +++ b/StarterNG/Services/LocalizationService.cs @@ -21,8 +21,22 @@ public class LocalizationService : INotifyPropertyChanged public string CurrentLangCode { get; private set; } = "en"; - public string this[string key] => - _strings.TryGetValue(key, out var value) ? value : key; + private readonly HashSet _reportedMisses = new(StringComparer.Ordinal); + + public string this[string key] + { + get + { + if (_strings.TryGetValue(key, out var value)) + return value; + + lock (_reportedMisses) + if (_reportedMisses.Add(key)) + Infrastructure.Diagnostics.Log($"lang/{CurrentLangCode}: missing key \"{key}\""); + + return key; + } + } public readonly record struct LanguageInfo(string Code, string Name, string Path); @@ -40,9 +54,9 @@ public class LocalizationService : INotifyPropertyChanged if (!string.IsNullOrEmpty(code)) list.Add(new LanguageInfo(code, string.IsNullOrEmpty(name) ? code : name, path)); } - catch + catch (Exception ex) { - + StarterNG.Infrastructure.Diagnostics.Log($"lang/{Path.GetFileName(path)}", ex); } } return list; @@ -114,6 +128,8 @@ public class LocalizationService : INotifyPropertyChanged } _strings = dict; + lock (_reportedMisses) + _reportedMisses.Clear(); CurrentLangCode = code; CurrentLanguage = name; } diff --git a/StarterNG/Views/Scenarios.axaml.cs b/StarterNG/Views/Scenarios.axaml.cs index fd40310..6dd58ef 100644 --- a/StarterNG/Views/Scenarios.axaml.cs +++ b/StarterNG/Views/Scenarios.axaml.cs @@ -391,7 +391,10 @@ public partial class Scenarios : UserControl { Process.Start(new ProcessStartInfo(full) { UseShellExecute = true }); } - catch { } + catch (Exception ex) + { + StarterNG.Infrastructure.Diagnostics.Log($"opening {full}", ex); + } } public void RebuildAfterLanguageChange() diff --git a/StarterNG/Views/TextureBaseWindow.axaml.cs b/StarterNG/Views/TextureBaseWindow.axaml.cs index 1a1dc1a..93be3da 100644 --- a/StarterNG/Views/TextureBaseWindow.axaml.cs +++ b/StarterNG/Views/TextureBaseWindow.axaml.cs @@ -210,4 +210,3 @@ internal sealed class TextureRow System.Globalization.DateTimeStyles.None, out var rev) ? rev : null; } } -