Skip to content

Commit

Permalink
[Settings]Better logging when upgrading settings from a old format (#…
Browse files Browse the repository at this point in the history
…22497)

* SettingUtils fixing error reporting when reading settings in old format

* Making the error message even more informative
  • Loading branch information
donlaci committed Dec 5, 2022
1 parent 42c77d7 commit ba9e244
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/settings-ui/Settings.UI.Library/SettingsUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,20 @@ public T GetSettingsOrDefault<T, T2>(string powertoy = DefaultModuleName, string
// This is different from the case where we have trailing zeros following a valid json file, which we have handled by trimming the trailing zeros.
catch (JsonException ex)
{
Logger.LogError($"Exception encountered while loading {powertoy} settings.", ex);
Logger.LogInfo($"Settings file {fileName} for {powertoy} was unrecognized. Possibly containing an older version. Trying to read again.");

// try to deserialize to the old format, which is presented in T2
try
{
T2 oldSettings = GetSettings<T2>(powertoy, fileName);
T newSettings = (T)settingsUpgrader(oldSettings);
Logger.LogInfo($"Settings file {fileName} for {powertoy} was read successfully in the old format.");
return newSettings;
}
catch (Exception)
{
// do nothing, the problem wasn't that the settings was stored in the previous format, continue with the default settings
Logger.LogError($"{powertoy} settings are corrupt or the format is not supported any longer. Using default settings instead.", ex);
}
}
catch (FileNotFoundException)
Expand Down

0 comments on commit ba9e244

Please sign in to comment.