Conditionally sanitize exceptions

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

@ -332,7 +332,7 @@ abstract class ActivityBilling extends ActivityBase implements PurchasesUpdatedL
} }
} catch (Throwable ex) { } catch (Throwable ex) {
Log.e(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(); editor.apply();

@ -633,7 +633,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
@Override @Override
protected void onException(Bundle args, Throwable ex) { 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"); }.execute(this, new Bundle(), "crash:log");
} }

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

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

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

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

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

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

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

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

Loading…
Cancel
Save