Improve error reporting: Extract original message when showing "Java exception messages" consistently. Improve error handling in deprecated OneDrive API stub and avoid crash by no-longer throwing in Main-thread methods.

This commit is contained in:
Philipp Crocoll
2025-04-15 11:45:16 +02:00
parent 8e256ac94d
commit dbf10ba9fb
30 changed files with 135 additions and 85 deletions

View File

@@ -28,7 +28,7 @@ namespace keepass2android
}
catch (Exception e)
{
Finish(false, e.Message);
Finish(false, Util.GetErrorMessage(e));
}
}

View File

@@ -796,7 +796,7 @@ namespace keepass2android
{
App.Kp2a.ShowMessage(this,
GetString(Resource.String.SaveAttachment_Failed, new Java.Lang.Object[] {filename})
+ exWrite.Message, MessageSeverity.Error);
+ Util.GetErrorMessage(exWrite), MessageSeverity.Error);
return null;
}
finally
@@ -1305,7 +1305,7 @@ namespace keepass2android
}
catch (Exception ex)
{
Finish(false, ex.Message);
Finish(false, Util.GetErrorMessage(ex));
}

View File

@@ -715,7 +715,7 @@ namespace keepass2android
}
catch(Exception exAttach)
{
App.Kp2a.ShowMessage(this, GetString(Resource.String.AttachFailed)+" "+exAttach.Message, MessageSeverity.Error);
App.Kp2a.ShowMessage(this, GetString(Resource.String.AttachFailed)+" "+ Util.GetErrorMessage(exAttach), MessageSeverity.Error);
}
State.EntryModified = true;
PopulateBinaries();
@@ -1184,7 +1184,7 @@ namespace keepass2android
}))
.AddOnFailureListener(new FailureListener((e) =>
{
Console.WriteLine($"Scan failed: {e.Message}");
Console.WriteLine($"Scan failed: {Util.GetErrorMessage(e)}");
}));

View File

@@ -140,7 +140,7 @@ namespace keepass2android
}
catch (Exception ex)
{
Finish(false, ex.Message);
Finish(false, Util.GetErrorMessage(ex));
}

View File

@@ -128,7 +128,7 @@ namespace keepass2android
catch (Exception e)
{
toastMsg = ctx.GetString(Resource.String.private_key_save_failed,
new Java.Lang.Object[] { e.Message });
new Java.Lang.Object[] { Util.GetErrorMessage(e)});
severity = MessageSeverity.Error;
}

View File

@@ -543,7 +543,7 @@ namespace keepass2android
}
catch (Exception e)
{
App.Kp2a.ShowMessage(this, e.Message, MessageSeverity.Error);
App.Kp2a.ShowMessage(this, Util.GetErrorMessage(e), MessageSeverity.Error);
}
return password;

View File

@@ -310,7 +310,7 @@ namespace keepass2android
catch (Exception e)
{
Kp2aLog.Log(e.ToString());
App.Kp2a.ShowMessage(this, "Error: " + e.Message, MessageSeverity.Error);
App.Kp2a.ShowMessage(this, "Error: " + Util.GetErrorMessage(e), MessageSeverity.Error);
return;
}
@@ -1485,7 +1485,7 @@ namespace keepass2android
catch (Exception e)
{
Kp2aLog.LogUnexpectedError(e);
errorMessage = e.Message;
errorMessage = Util.GetErrorMessage(e);
return false;
}
}
@@ -2273,7 +2273,7 @@ namespace keepass2android
{
Kp2aLog.LogUnexpectedError(e);
ShowError( _act.GetString(Resource.String.ErrorUpdatingOtpAuxFile) + " " + e.Message);
ShowError( _act.GetString(Resource.String.ErrorUpdatingOtpAuxFile) + " " + Util.GetErrorMessage(e));
}

View File

@@ -121,7 +121,7 @@ namespace keepass2android
} catch (Exception e)
{
App.Kp2a.ShowMessage(this, e.Message, MessageSeverity.Error);
App.Kp2a.ShowMessage(this, Util.GetErrorMessage(e), MessageSeverity.Error);
SetResult(Result.Canceled);
Finish();
return;

View File

@@ -40,7 +40,7 @@ namespace keepass2android
catch (Exception e)
{
Finish(false, e.Message);
Finish(false, Util.GetErrorMessage(e));
}

View File

@@ -37,10 +37,12 @@ using Android.Util;
using Android.Views.InputMethods;
using AndroidX.Core.View.InputMethod;
using Google.Android.Material.Dialog;
using KeePass.Util;
using keepass2android;
using KeePassLib;
using KeePassLib.Security;
using KeePassLib.Serialization;
using Org.Apache.Http.Util;
using Uri = Android.Net.Uri;
@@ -198,6 +200,12 @@ namespace keepass2android
ioc.CredSaveMode = (IOCredSaveMode)i.GetIntExtra(prefix + KeyServercredmode, (int)IOCredSaveMode.NoSave);
}
public static string GetErrorMessage(Exception e)
{
return ExceptionUtil.GetErrorMessage(e);
}
public static Bitmap DrawableToBitmap(Drawable drawable)
{
Bitmap bitmap = null;
@@ -865,8 +873,6 @@ namespace keepass2android
entry.Strings.Set(prefix + c, new ProtectedString(false, url));
}
}
}

View File

@@ -836,7 +836,7 @@ namespace keepass2android
new DropboxAppFolderFileStorage(LocaleManager.LocalizedAppContext, this),
GoogleApiAvailability.Instance.IsGooglePlayServicesAvailable(LocaleManager.LocalizedAppContext)==ConnectionResult.Success ? new GoogleDriveFileStorage(LocaleManager.LocalizedAppContext, this) : null,
GoogleApiAvailability.Instance.IsGooglePlayServicesAvailable(LocaleManager.LocalizedAppContext)==ConnectionResult.Success ? new GoogleDriveAppDataFileStorage(LocaleManager.LocalizedAppContext, this) : null,
new OneDriveFileStorage(),
new OneDriveFileStorage(this),
new OneDrive2FullFileStorage(),
new OneDrive2MyFilesFileStorage(),
new OneDrive2AppFolderFileStorage(),
@@ -1043,9 +1043,9 @@ namespace keepass2android
}
private string GetErrorMessageForFileStorageException(Exception e)
{
string errorMessage = e.Message;
if (e is OfflineModeException)
{
var errorMessage = Util.GetErrorMessage(e);
if (e is OfflineModeException)
errorMessage = GetResourceString(UiStringKey.InOfflineMode);
if (e is DocumentAccessRevokedException)
errorMessage = GetResourceString(UiStringKey.DocumentAccessRevoked);
@@ -1054,7 +1054,7 @@ namespace keepass2android
}
public void CouldntOpenFromRemote(IOConnectionInfo ioc, Exception ex)
public void CouldntOpenFromRemote(IOConnectionInfo ioc, Exception ex)
{
var errorMessage = GetErrorMessageForFileStorageException(ex);
ShowToast(LocaleManager.LocalizedAppContext.GetString(Resource.String.CouldNotLoadFromRemote, errorMessage), MessageSeverity.Error);

View File

@@ -71,7 +71,7 @@ namespace keepass2android
catch (Exception e)
{
if (errorMessageBuilder != null)
errorMessageBuilder.Append(e.Message);
errorMessageBuilder.Append(Util.GetErrorMessage(e));
Kp2aLog.Log(e.ToString());
return null;
}

View File

@@ -487,7 +487,7 @@ namespace keepass2android
catch (Exception e)
{
Kp2aLog.LogUnexpectedError(e);
App.Kp2a.ShowMessage(this, "Error: " + e.Message, MessageSeverity.Error);
App.Kp2a.ShowMessage(this, "Error: " + Util.GetErrorMessage(e), MessageSeverity.Error);
Finish();
}

View File

@@ -142,7 +142,7 @@ namespace keepass2android.search
}
} catch (Exception e) {
Kp2aLog.LogUnexpectedError(e);
App.Kp2a.ShowMessage(this,e.Message, MessageSeverity.Error);
App.Kp2a.ShowMessage(this, Util.GetErrorMessage(e), MessageSeverity.Error);
Finish();
return;
}

View File

@@ -96,7 +96,7 @@ namespace keepass2android.search
catch (Exception e)
{
Kp2aLog.LogUnexpectedError(e);
App.Kp2a.ShowMessage(this, e.Message, MessageSeverity.Error);
App.Kp2a.ShowMessage(this, Util.GetErrorMessage(e), MessageSeverity.Error);
Finish();
return;
}

View File

@@ -156,7 +156,7 @@ namespace keepass2android.services.AutofillBase
catch (Java.Lang.SecurityException e)
{
Log.Warn(CommonUtil.Tag, "Security exception handling request");
callback.OnFailure(e.Message);
callback.OnFailure(Util.GetErrorMessage(e));
return;
}
@@ -455,7 +455,7 @@ namespace keepass2android.services.AutofillBase
}
catch (Exception e)
{
callback.OnFailure(e.Message);
callback.OnFailure(Util.GetErrorMessage(e));
}
}

View File

@@ -261,7 +261,7 @@ namespace keepass2android
{
return () =>
{
App.Kp2a.ShowMessage(Activity, App.Kp2a.GetResourceString(UiStringKey.ErrorOcurred) + " " + e.Message, MessageSeverity.Error);
App.Kp2a.ShowMessage(Activity, App.Kp2a.GetResourceString(UiStringKey.ErrorOcurred) + " " + Util.GetErrorMessage(e), MessageSeverity.Error);
};
}
@@ -357,7 +357,7 @@ namespace keepass2android
{
return () =>
{
App.Kp2a.ShowMessage(Activity, App.Kp2a.GetResourceString(UiStringKey.ErrorOcurred) + " " + e.Message, MessageSeverity.Error);
App.Kp2a.ShowMessage(Activity, App.Kp2a.GetResourceString(UiStringKey.ErrorOcurred) + " " + Util.GetErrorMessage(e), MessageSeverity.Error);
};
}
@@ -628,7 +628,7 @@ namespace keepass2android
catch (Exception ex)
{
Kp2aLog.LogUnexpectedError(ex);
App.Kp2a.ShowMessage(LocaleManager.LocalizedAppContext, ex.Message, MessageSeverity.Error);
App.Kp2a.ShowMessage(LocaleManager.LocalizedAppContext, Util.GetErrorMessage(ex), MessageSeverity.Error);
}
}
);

View File

@@ -53,7 +53,7 @@ namespace keepass2android
}
catch (Exception ex)
{
Finish(false, ex.Message);
Finish(false, Util.GetErrorMessage(ex));
}