From cafc78636797282525e6817685cfa6f2e0ff22eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wolf-Martell=20Montw=C3=A9?= Date: Tue, 29 Aug 2023 19:10:37 +0200 Subject: [PATCH] Add error messages to allow better import debugging --- .../java/com/fsck/k9/preferences/Settings.java | 7 +++++++ .../fsck/k9/preferences/SettingsImporter.java | 16 ++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/app/core/src/main/java/com/fsck/k9/preferences/Settings.java b/app/core/src/main/java/com/fsck/k9/preferences/Settings.java index 1aa80b3a5..dcff73e46 100644 --- a/app/core/src/main/java/com/fsck/k9/preferences/Settings.java +++ b/app/core/src/main/java/com/fsck/k9/preferences/Settings.java @@ -243,6 +243,13 @@ public class Settings { static class InvalidSettingValueException extends Exception { private static final long serialVersionUID = 1L; + + public InvalidSettingValueException() { + } + + public InvalidSettingValueException(String message) { + super(message); + } } /** diff --git a/app/core/src/main/java/com/fsck/k9/preferences/SettingsImporter.java b/app/core/src/main/java/com/fsck/k9/preferences/SettingsImporter.java index 3d9b26170..f7308902c 100644 --- a/app/core/src/main/java/com/fsck/k9/preferences/SettingsImporter.java +++ b/app/core/src/main/java/com/fsck/k9/preferences/SettingsImporter.java @@ -253,8 +253,12 @@ public class SettingsImporter { erroneousAccounts.add(importResult.original); } } catch (InvalidSettingValueException e) { - Timber.e(e, "Encountered invalid setting while importing account \"%s\"", - account.name); + String reason = e.getMessage(); + if (TextUtils.isEmpty(reason)) { + reason = "Unknown"; + } + Timber.e(e, "Encountered invalid setting while importing account \"%s\", reason: \"%s\"", + account.name, reason); erroneousAccounts.add(new AccountDescription(account.name, account.uuid)); } catch (Exception e) { @@ -363,7 +367,7 @@ public class SettingsImporter { if (account.incoming == null) { // We don't import accounts without incoming server settings - throw new InvalidSettingValueException(); + throw new InvalidSettingValueException("Missing incoming server settings"); } // Write incoming server settings @@ -380,7 +384,7 @@ public class SettingsImporter { boolean authorizationNeeded = incoming.authenticationType == AuthType.XOAUTH2; if (account.outgoing == null) { - throw new InvalidSettingValueException(); + throw new InvalidSettingValueException("Missing outgoing server settings"); } String outgoingServerName = null; @@ -448,7 +452,7 @@ public class SettingsImporter { importIdentities(editor, contentVersion, uuid, account, overwrite, existingAccount, prefs); } else if (!mergeImportedAccount) { // Require accounts to at least have one identity - throw new InvalidSettingValueException(); + throw new InvalidSettingValueException("Missing identities, there should be at least one."); } // Write folder settings @@ -541,7 +545,7 @@ public class SettingsImporter { // Validate email address if (!IdentitySettingsDescriptions.isEmailAddressValid(identity.email)) { - throw new InvalidSettingValueException(); + throw new InvalidSettingValueException("Invalid email address: " + identity.email); } // Write email address