Conditionally sanitize exceptions

pull/157/head
M66B 5 years ago
parent 4cc1ed3a85
commit 286a6a9720

@ -332,7 +332,7 @@ abstract class ActivityBilling extends ActivityBase implements PurchasesUpdatedL
}
} catch (Throwable ex) {
Log.e(ex);
Toast.makeText(this, Helper.formatThrowable(ex), Toast.LENGTH_LONG).show();
Toast.makeText(this, Helper.formatThrowable(ex, false), Toast.LENGTH_LONG).show();
}
editor.apply();

@ -633,7 +633,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
@Override
protected void onException(Bundle args, Throwable ex) {
Toast.makeText(ActivityView.this, Helper.formatThrowable(ex), Toast.LENGTH_LONG).show();
Toast.makeText(ActivityView.this, Helper.formatThrowable(ex, false), Toast.LENGTH_LONG).show();
}
}.execute(this, new Bundle(), "crash:log");
}

@ -246,7 +246,7 @@ class Core {
db.operation().deleteOperation(op.id);
} catch (Throwable ex) {
Log.e(folder.name, ex);
EntityLog.log(context, folder.name + " " + Helper.formatThrowable(ex));
EntityLog.log(context, folder.name + " " + Helper.formatThrowable(ex, false));
db.operation().setOperationError(op.id, Helper.formatThrowable(ex));
if (message != null && !(ex instanceof IllegalArgumentException))
@ -1075,7 +1075,7 @@ class Core {
Log.w(folder.name, ex);
} catch (Throwable ex) {
Log.e(folder.name, ex);
EntityLog.log(context, folder.name + " " + Helper.formatThrowable(ex));
EntityLog.log(context, folder.name + " " + Helper.formatThrowable(ex, false));
db.folder().setFolderError(folder.id, Helper.formatThrowable(ex));
}
@ -2163,7 +2163,7 @@ class Core {
new NotificationCompat.Builder(context, channel)
.setSmallIcon(R.drawable.baseline_warning_white_24)
.setContentTitle(context.getString(R.string.title_notification_failed, title))
.setContentText(Helper.formatThrowable(ex))
.setContentText(Helper.formatThrowable(ex, false))
.setContentIntent(pi)
.setAutoCancel(false)
.setShowWhen(true)
@ -2173,7 +2173,7 @@ class Core {
.setVisibility(NotificationCompat.VISIBILITY_SECRET);
builder.setStyle(new NotificationCompat.BigTextStyle()
.bigText(Helper.formatThrowable(ex, "\n")));
.bigText(Helper.formatThrowable(ex, "\n", false)));
return builder;
}

@ -1073,7 +1073,7 @@ public class FragmentAccount extends FragmentBase {
}
private void showError(Throwable ex) {
tvError.setText(Helper.formatThrowable(ex));
tvError.setText(Helper.formatThrowable(ex, false));
tvError.setVisibility(View.VISIBLE);
final View target;

@ -803,7 +803,7 @@ public class FragmentIdentity extends FragmentBase {
}
private void showError(Throwable ex) {
tvError.setText(Helper.formatThrowable(ex));
tvError.setText(Helper.formatThrowable(ex, false));
tvError.setVisibility(View.VISIBLE);
final View target;

@ -2887,7 +2887,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG).show();
else
new DialogBuilderLifecycle(getContext(), getViewLifecycleOwner())
.setMessage(Helper.formatThrowable(ex))
.setMessage(Helper.formatThrowable(ex, false))
.setPositiveButton(android.R.string.cancel, null)
.create()
.show();

@ -386,7 +386,7 @@ public class FragmentQuickSetup extends FragmentBase {
if (ex instanceof IllegalArgumentException || ex instanceof UnknownHostException)
Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG).show();
else {
tvError.setText(Helper.formatThrowable(ex));
tvError.setText(Helper.formatThrowable(ex, false));
tvError.setVisibility(View.VISIBLE);
}
}

@ -382,27 +382,33 @@ public class Helper {
}
static String formatThrowable(Throwable ex) {
return formatThrowable(ex, " ");
return formatThrowable(ex, true);
}
static String formatThrowable(Throwable ex, String separator) {
if (ex instanceof MessageRemovedException)
return null;
static String formatThrowable(Throwable ex, boolean santize) {
return formatThrowable(ex, " ", santize);
}
if (ex instanceof IOException &&
ex.getCause() instanceof MessageRemovedException)
return null;
static String formatThrowable(Throwable ex, String separator, boolean sanitize) {
if (sanitize) {
if (ex instanceof MessageRemovedException)
return null;
if (ex instanceof FolderClosedException)
return null;
if (ex instanceof IOException &&
ex.getCause() instanceof MessageRemovedException)
return null;
if (ex instanceof IllegalStateException &&
("Not connected".equals(ex.getMessage()) ||
"This operation is not allowed on a closed folder".equals(ex.getMessage())))
return null;
if (ex instanceof FolderClosedException)
return null;
if (ex instanceof Core.AlertException)
return ex.getMessage();
if (ex instanceof IllegalStateException &&
("Not connected".equals(ex.getMessage()) ||
"This operation is not allowed on a closed folder".equals(ex.getMessage())))
return null;
if (ex instanceof Core.AlertException)
return ex.getMessage();
}
StringBuilder sb = new StringBuilder();
if (BuildConfig.DEBUG)

@ -806,7 +806,7 @@ public class MessageHelper {
throw ex;
} catch (Throwable ex) {
Log.w(ex);
warnings.add(Helper.formatThrowable(ex));
warnings.add(Helper.formatThrowable(ex, false));
return null;
}
@ -828,7 +828,7 @@ public class MessageHelper {
}
} catch (ParseException ex) {
Log.w(ex);
warnings.add(Helper.formatThrowable(ex));
warnings.add(Helper.formatThrowable(ex, false));
}
result = result.replace("\0", "");
@ -932,7 +932,7 @@ public class MessageHelper {
// https://javaee.github.io/javamail/FAQ#imapserverbug
if ("Unable to load BODYSTRUCTURE".equals(ex.getMessage())) {
Log.w(ex);
parts.warnings.add(Helper.formatThrowable(ex));
parts.warnings.add(Helper.formatThrowable(ex, false));
try {
cmessage = new MimeMessage(imessage);
} catch (MessagingException ignored) {
@ -970,7 +970,7 @@ public class MessageHelper {
// Nested body: try to continue
// ParseException: In parameter list boundary="...">, expected parameter name, got ";"
Log.w(ex);
parts.warnings.add(Helper.formatThrowable(ex));
parts.warnings.add(Helper.formatThrowable(ex, false));
}
} else {
// https://www.iana.org/assignments/cont-disp/cont-disp.xhtml
@ -981,7 +981,7 @@ public class MessageHelper {
disposition = disposition.toLowerCase();
} catch (MessagingException ex) {
Log.w(ex);
parts.warnings.add(Helper.formatThrowable(ex));
parts.warnings.add(Helper.formatThrowable(ex, false));
disposition = null;
}
@ -990,7 +990,7 @@ public class MessageHelper {
filename = part.getFileName();
} catch (MessagingException ex) {
Log.w(ex);
parts.warnings.add(Helper.formatThrowable(ex));
parts.warnings.add(Helper.formatThrowable(ex, false));
filename = null;
}
@ -1018,7 +1018,7 @@ public class MessageHelper {
ct = new ContentType(apart.part.getContentType());
} catch (ParseException ex) {
Log.w(ex);
parts.warnings.add(Helper.formatThrowable(ex));
parts.warnings.add(Helper.formatThrowable(ex, false));
ct = new ContentType("application/octet-stream");
}
@ -1027,7 +1027,7 @@ public class MessageHelper {
cid = apart.part.getHeader("Content-ID");
} catch (MessagingException ex) {
Log.w(ex);
parts.warnings.add(Helper.formatThrowable(ex));
parts.warnings.add(Helper.formatThrowable(ex, false));
}
apart.attachment = new EntityAttachment();
@ -1072,7 +1072,7 @@ public class MessageHelper {
throw ex;
} catch (MessagingException ex) {
Log.w(ex);
parts.warnings.add(Helper.formatThrowable(ex));
parts.warnings.add(Helper.formatThrowable(ex, false));
}
}

@ -153,7 +153,7 @@ public class ServiceSend extends LifecycleService {
Log.e(outbox.name, ex);
EntityLog.log(
ServiceSend.this,
outbox.name + " " + Helper.formatThrowable(ex));
outbox.name + " " + Helper.formatThrowable(ex, false));
db.operation().setOperationError(op.id, Helper.formatThrowable(ex));
if (message != null)

@ -600,7 +600,7 @@ public class ServiceSynchronize extends LifecycleService {
Log.w(account.name + " alert: " + message);
EntityLog.log(
ServiceSynchronize.this, account.name + " " +
Helper.formatThrowable(new Core.AlertException(message)));
Helper.formatThrowable(new Core.AlertException(message), false));
db.account().setAccountError(account.id, message);
if (message != null && !message.startsWith("Too many simultaneous connections")) {
@ -855,7 +855,7 @@ public class ServiceSynchronize extends LifecycleService {
Log.e(folder.name, ex);
EntityLog.log(
ServiceSynchronize.this,
folder.name + " " + Helper.formatThrowable(ex));
folder.name + " " + Helper.formatThrowable(ex, false));
state.error(ex);
} finally {
wlMessage.release();
@ -888,7 +888,7 @@ public class ServiceSynchronize extends LifecycleService {
Log.e(folder.name, ex);
EntityLog.log(
ServiceSynchronize.this,
folder.name + " " + Helper.formatThrowable(ex));
folder.name + " " + Helper.formatThrowable(ex, false));
db.folder().setFolderError(folder.id, Helper.formatThrowable(ex));
state.error(ex);
} finally {
@ -944,7 +944,7 @@ public class ServiceSynchronize extends LifecycleService {
Log.e(folder.name, ex);
EntityLog.log(
ServiceSynchronize.this,
folder.name + " " + Helper.formatThrowable(ex));
folder.name + " " + Helper.formatThrowable(ex, false));
state.error(ex);
} finally {
wlMessage.release();
@ -966,7 +966,7 @@ public class ServiceSynchronize extends LifecycleService {
Log.e(folder.name, ex);
EntityLog.log(
ServiceSynchronize.this,
folder.name + " " + Helper.formatThrowable(ex));
folder.name + " " + Helper.formatThrowable(ex, false));
state.error(new FolderClosedException(ifolder, "IDLE"));
} finally {
Log.i(folder.name + " end idle");
@ -1047,7 +1047,7 @@ public class ServiceSynchronize extends LifecycleService {
Log.e(folder.name, ex);
EntityLog.log(
ServiceSynchronize.this,
folder.name + " " + Helper.formatThrowable(ex));
folder.name + " " + Helper.formatThrowable(ex, false));
db.folder().setFolderError(folder.id, Helper.formatThrowable(ex));
state.error(ex);
} finally {
@ -1162,7 +1162,7 @@ public class ServiceSynchronize extends LifecycleService {
Log.e(account.name, ex);
EntityLog.log(
ServiceSynchronize.this,
account.name + " " + Helper.formatThrowable(ex));
account.name + " " + Helper.formatThrowable(ex, false));
db.account().setAccountError(account.id, Helper.formatThrowable(ex));
} finally {
// Stop watching for operations

Loading…
Cancel
Save