Add better handling for database decryption failures

This commit is contained in:
Łukasz Domeradzki
2025-12-19 10:26:08 +01:00
parent da33797b18
commit b79b702c4d
2 changed files with 16 additions and 0 deletions

View File

@@ -803,4 +803,8 @@ Process uptime: {1}</value>
<data name="WarningNoSystemRequiredLinuxDependencies" xml:space="preserve">
<value>You've declared --system-required, although your OS is missing required dependencies for that feature to work. Consider installing dbus, although you can also safely ignore this warning if you do not require inhibition to work properly.</value>
</data>
<data name="WarningBotDatabaseComponentDecryptionFailed" xml:space="preserve">
<value>Decryption of {0} database component has failed. This can be OK if you've just changed your bot's {1}, you should no longer observe this warning on the next run then. Otherwise, you should investigate and find out the exact reason for failure.</value>
<comment>{0} will be replaced by bot database component's name (string), {1} will be replaced by bot config component's name (string).</comment>
</data>
</root>

View File

@@ -2496,10 +2496,22 @@ public sealed class Bot : IAsyncDisposable, IDisposable {
if (BotConfig.PasswordFormat.HasTransformation()) {
if (!string.IsNullOrEmpty(accessTokenText)) {
accessTokenText = await ArchiCryptoHelper.Decrypt(BotConfig.PasswordFormat, accessTokenText).ConfigureAwait(false);
if (string.IsNullOrEmpty(accessTokenText)) {
BotDatabase.AccessToken = null;
ArchiLogger.LogGenericWarning(Strings.FormatWarningBotDatabaseComponentDecryptionFailed(nameof(BotDatabase.AccessToken), nameof(BotConfig.PasswordFormat)));
}
}
if (!string.IsNullOrEmpty(refreshTokenText)) {
refreshTokenText = await ArchiCryptoHelper.Decrypt(BotConfig.PasswordFormat, refreshTokenText).ConfigureAwait(false);
if (string.IsNullOrEmpty(refreshTokenText)) {
BotDatabase.RefreshToken = null;
ArchiLogger.LogGenericWarning(Strings.FormatWarningBotDatabaseComponentDecryptionFailed(nameof(BotDatabase.RefreshToken), nameof(BotConfig.PasswordFormat)));
}
}
}