Skip to content

Commit

Permalink
Add error messages to allow better import debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
wmontwe committed Aug 29, 2023
1 parent 1d350ec commit cafc786
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
7 changes: 7 additions & 0 deletions app/core/src/main/java/com/fsck/k9/preferences/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,13 @@ static TreeMap<Integer, SettingsDescription> versions(V... versionDescriptions)

static class InvalidSettingValueException extends Exception {
private static final long serialVersionUID = 1L;

public InvalidSettingValueException() {
}

public InvalidSettingValueException(String message) {
super(message);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,12 @@ public static ImportResults importSettings(Context context, InputStream inputStr
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) {
Expand Down Expand Up @@ -363,7 +367,7 @@ private static AccountDescriptionPair importAccount(Context context, StorageEdit

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
Expand All @@ -380,7 +384,7 @@ private static AccountDescriptionPair importAccount(Context context, StorageEdit
boolean authorizationNeeded = incoming.authenticationType == AuthType.XOAUTH2;

if (account.outgoing == null) {
throw new InvalidSettingValueException();
throw new InvalidSettingValueException("Missing outgoing server settings");
}

String outgoingServerName = null;
Expand Down Expand Up @@ -448,7 +452,7 @@ private static AccountDescriptionPair importAccount(Context context, StorageEdit
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
Expand Down Expand Up @@ -541,7 +545,7 @@ private static void importIdentities(StorageEditor editor, int contentVersion, S

// Validate email address
if (!IdentitySettingsDescriptions.isEmailAddressValid(identity.email)) {
throw new InvalidSettingValueException();
throw new InvalidSettingValueException("Invalid email address: " + identity.email);
}

// Write email address
Expand Down

0 comments on commit cafc786

Please sign in to comment.