Throwable wrapper

pull/214/head
M66B 9 months ago
parent cbcc467408
commit d56b5fa43e

@ -621,7 +621,7 @@ public class ActivityEML extends ActivityBase {
@Override
protected void onException(Bundle args, @NonNull Throwable ex) {
if (ex instanceof IllegalArgumentException)
Snackbar.make(findViewById(android.R.id.content), ex.getMessage(), Snackbar.LENGTH_LONG)
Snackbar.make(findViewById(android.R.id.content), new ThrowableWrapper(ex).getSafeMessage(), Snackbar.LENGTH_LONG)
.setGestureInsetBottomIgnored(true).show();
else
Log.unexpectedError(getSupportFragmentManager(), ex);

@ -866,7 +866,7 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
@Override
protected void onException(Bundle args, Throwable ex) {
if (ex instanceof IllegalStateException) {
Snackbar snackbar = Snackbar.make(parentFragment.getView(), ex.getMessage(), Snackbar.LENGTH_LONG)
Snackbar snackbar = Snackbar.make(parentFragment.getView(), new ThrowableWrapper(ex).getSafeMessage(), Snackbar.LENGTH_LONG)
.setGestureInsetBottomIgnored(true);
snackbar.setAction(R.string.title_fix, new View.OnClickListener() {
@Override
@ -878,7 +878,7 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
});
snackbar.show();
} else if (ex instanceof IllegalArgumentException)
Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG)
Snackbar.make(view, new ThrowableWrapper(ex).getSafeMessage(), Snackbar.LENGTH_LONG)
.setGestureInsetBottomIgnored(true).show();
else
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);

@ -3450,7 +3450,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
@Override
protected void onException(Bundle args, Throwable ex) {
if (ex instanceof OutOfMemoryError)
Snackbar.make(parentFragment.getView(), ex.getMessage(), Snackbar.LENGTH_LONG)
Snackbar.make(parentFragment.getView(), new ThrowableWrapper(ex).getSafeMessage(), Snackbar.LENGTH_LONG)
.setGestureInsetBottomIgnored(true).show();
else
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);

@ -701,10 +701,10 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
if (ex instanceof ProtocolException) {
Response r = ((ProtocolException) ex).getResponse();
if (r != null && !TextUtils.isEmpty(r.getRest()))
return r.getRest();
return r.getRest(); // TODO CASA ?
}
return ex.toString();
return new ThrowableWrapper(ex).toSafeString();
}
private Message[] search(boolean utf8, String[] keywords, IMAPProtocol protocol, State state) throws IOException, MessagingException, ProtocolException {

@ -494,6 +494,7 @@ public abstract class DB extends RoomDatabase {
if (cache_size != null) {
cache_size = -cache_size; // kibibytes
Log.i("Set PRAGMA cache_size=" + cache_size);
// TODO CASA
try (Cursor cursor = jni_safe_support_query(db, "PRAGMA cache_size=" + cache_size + ";", new Object[0])) {
cursor.moveToNext(); // required
}
@ -514,6 +515,7 @@ public abstract class DB extends RoomDatabase {
// https://www.sqlite.org/pragma.html
for (String pragma : DB_PRAGMAS)
if (!"compile_options".equals(pragma) || BuildConfig.DEBUG) {
// TODO CASA
try (Cursor cursor = jni_safe_support_query(db, "PRAGMA " + pragma + ";", new Object[0])) {
boolean has = false;
while (cursor.moveToNext()) {

@ -707,7 +707,7 @@ public class FragmentAccount extends FragmentBase {
(ex instanceof UnknownHostException ||
ex instanceof FileNotFoundException ||
ex instanceof IllegalArgumentException))
Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG)
Snackbar.make(view, new ThrowableWrapper(ex).getSafeMessage(), Snackbar.LENGTH_LONG)
.setGestureInsetBottomIgnored(true).show();
else
Log.unexpectedError(getParentFragmentManager(), ex);
@ -887,7 +887,7 @@ public class FragmentAccount extends FragmentBase {
cbIdentity.setVisibility(View.GONE);
if (ex instanceof IllegalArgumentException)
Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG)
Snackbar.make(view, new ThrowableWrapper(ex).getSafeMessage(), Snackbar.LENGTH_LONG)
.setGestureInsetBottomIgnored(true).show();
else
showError(ex);
@ -1521,7 +1521,7 @@ public class FragmentAccount extends FragmentBase {
@Override
protected void onException(Bundle args, Throwable ex) {
if (ex instanceof IllegalArgumentException)
Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG)
Snackbar.make(view, new ThrowableWrapper(ex).getSafeMessage(), Snackbar.LENGTH_LONG)
.setGestureInsetBottomIgnored(true).show();
else
showError(ex);

@ -532,7 +532,7 @@ public class FragmentAccounts extends FragmentBase {
@Override
protected void onException(Bundle args, Throwable ex) {
if (ex instanceof IllegalStateException) {
Snackbar snackbar = Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG)
Snackbar snackbar = Snackbar.make(view, new ThrowableWrapper(ex).getSafeMessage(), Snackbar.LENGTH_LONG)
.setGestureInsetBottomIgnored(true);
snackbar.setAction(R.string.title_fix, new View.OnClickListener() {
@Override
@ -544,7 +544,7 @@ public class FragmentAccounts extends FragmentBase {
});
snackbar.show();
} else if (ex instanceof IllegalArgumentException)
Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG)
Snackbar.make(view, new ThrowableWrapper(ex).getSafeMessage(), Snackbar.LENGTH_LONG)
.setGestureInsetBottomIgnored(true).show();
else
Log.unexpectedError(getParentFragmentManager(), ex);

@ -536,7 +536,7 @@ public class FragmentAnswer extends FragmentBase {
@Override
protected void onException(Bundle args, Throwable ex) {
if (ex instanceof IllegalArgumentException)
Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG)
Snackbar.make(view, new ThrowableWrapper(ex).getSafeMessage(), Snackbar.LENGTH_LONG)
.setGestureInsetBottomIgnored(true).show();
else
Log.unexpectedError(getParentFragmentManager(), ex);

@ -734,7 +734,7 @@ public class FragmentBase extends Fragment {
@RequiresApi(api = Build.VERSION_CODES.Q)
private void handle(RecoverableSecurityException ex) {
new AlertDialog.Builder(getContext())
.setMessage(ex.getMessage())
.setMessage(new ThrowableWrapper(ex).getSafeMessage())
.setPositiveButton(ex.getUserAction().getTitle(), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {

@ -1198,7 +1198,7 @@ public class FragmentCompose extends FragmentBase {
return MessageHelper.formatAddressesCompose(new Address[]{address});
} catch (Throwable ex) {
Log.e(ex);
return ex.toString();
return new ThrowableWrapper(ex).toSafeString();
}
}
});
@ -3223,7 +3223,7 @@ public class FragmentCompose extends FragmentBase {
onPgp(intent);
} catch (Throwable ex) {
if (ex instanceof IllegalArgumentException)
Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG)
Snackbar.make(view, new ThrowableWrapper(ex).getSafeMessage(), Snackbar.LENGTH_LONG)
.setGestureInsetBottomIgnored(true).show();
else {
Log.e(ex);
@ -4202,7 +4202,7 @@ public class FragmentCompose extends FragmentBase {
if (ex instanceof IllegalArgumentException
|| ex instanceof GeneralSecurityException /* InvalidKeyException */) {
Log.i(ex);
Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG)
Snackbar.make(view, new ThrowableWrapper(ex).getSafeMessage(), Snackbar.LENGTH_LONG)
.setGestureInsetBottomIgnored(true).show();
} else if (ex instanceof OperationCanceledException) {
Snackbar snackbar = Snackbar.make(view, R.string.title_no_openpgp, Snackbar.LENGTH_INDEFINITE)
@ -4563,7 +4563,7 @@ public class FragmentCompose extends FragmentBase {
protected void onException(Bundle args, Throwable ex) {
if (ex instanceof IllegalArgumentException) {
Log.i(ex);
Snackbar snackbar = Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_INDEFINITE)
Snackbar snackbar = Snackbar.make(view, new ThrowableWrapper(ex).getSafeMessage(), Snackbar.LENGTH_INDEFINITE)
.setGestureInsetBottomIgnored(true);
Helper.setSnackbarLines(snackbar, 7);
snackbar.setAction(R.string.title_fix, new View.OnClickListener() {
@ -6582,7 +6582,7 @@ public class FragmentCompose extends FragmentBase {
at android.content.ContentResolver.openInputStream(ContentResolver.java:1187)
at eu.faircode.email.FragmentCompose.addAttachment(SourceFile:27)
*/
Snackbar.make(view, ex.toString(), Snackbar.LENGTH_LONG)
Snackbar.make(view, new ThrowableWrapper(ex).toSafeString(), Snackbar.LENGTH_LONG)
.setGestureInsetBottomIgnored(true).show();
} else {
if (ex instanceof IOException &&

@ -321,7 +321,7 @@ public class FragmentDialogTranslate extends FragmentDialogBase {
@Override
protected void onException(Bundle args, Throwable ex) {
tvText.setText(ex.toString());
tvText.setText(new ThrowableWrapper(ex).toSafeString());
}
}.execute(this, getArguments(), "message:translate");

@ -719,7 +719,7 @@ public class FragmentFolder extends FragmentBase {
@Override
protected void onException(Bundle args, Throwable ex) {
if (ex instanceof IllegalArgumentException)
Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG)
Snackbar.make(view, new ThrowableWrapper(ex).getSafeMessage(), Snackbar.LENGTH_LONG)
.setGestureInsetBottomIgnored(true).show();
else
Log.unexpectedError(getParentFragmentManager(), ex, !(ex instanceof SQLiteConstraintException));
@ -778,7 +778,7 @@ public class FragmentFolder extends FragmentBase {
pbSave.setVisibility(View.GONE);
if (ex instanceof IllegalArgumentException)
Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG)
Snackbar.make(view, new ThrowableWrapper(ex).getSafeMessage(), Snackbar.LENGTH_LONG)
.setGestureInsetBottomIgnored(true).show();
else
Log.unexpectedError(getParentFragmentManager(), ex);

@ -616,7 +616,7 @@ public class FragmentFolders extends FragmentBase {
@Override
protected void onException(Bundle args, Throwable ex) {
if (ex instanceof IllegalStateException) {
Snackbar snackbar = Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG)
Snackbar snackbar = Snackbar.make(view, new ThrowableWrapper(ex).getSafeMessage(), Snackbar.LENGTH_LONG)
.setGestureInsetBottomIgnored(true);
snackbar.setAction(R.string.title_fix, new View.OnClickListener() {
@Override
@ -628,7 +628,7 @@ public class FragmentFolders extends FragmentBase {
});
snackbar.show();
} else if (ex instanceof IllegalArgumentException)
Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG)
Snackbar.make(view, new ThrowableWrapper(ex).getSafeMessage(), Snackbar.LENGTH_LONG)
.setGestureInsetBottomIgnored(true).show();
else
Log.unexpectedError(getParentFragmentManager(), ex);

@ -708,7 +708,7 @@ public class FragmentIdentity extends FragmentBase {
(ex instanceof UnknownHostException ||
ex instanceof FileNotFoundException ||
ex instanceof IllegalArgumentException))
Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG)
Snackbar.make(view, new ThrowableWrapper(ex).getSafeMessage(), Snackbar.LENGTH_LONG)
.setGestureInsetBottomIgnored(true).show();
else
Log.unexpectedError(getParentFragmentManager(), ex);
@ -1167,7 +1167,7 @@ public class FragmentIdentity extends FragmentBase {
@Override
protected void onException(Bundle args, Throwable ex) {
if (ex instanceof IllegalArgumentException)
Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG)
Snackbar.make(view, new ThrowableWrapper(ex).getSafeMessage(), Snackbar.LENGTH_LONG)
.setGestureInsetBottomIgnored(true).show();
else
showError(ex);

@ -2393,7 +2393,7 @@ public class FragmentMessages extends FragmentBase
@Override
protected void onException(Bundle args, Throwable ex) {
if (ex instanceof IllegalStateException) {
Snackbar snackbar = Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG)
Snackbar snackbar = Snackbar.make(view, new ThrowableWrapper(ex).getSafeMessage(), Snackbar.LENGTH_LONG)
.setGestureInsetBottomIgnored(true);
snackbar.setAction(R.string.title_fix, new View.OnClickListener() {
@Override
@ -2405,7 +2405,7 @@ public class FragmentMessages extends FragmentBase
});
snackbar.show();
} else if (ex instanceof IllegalArgumentException)
Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG)
Snackbar.make(view, new ThrowableWrapper(ex).getSafeMessage(), Snackbar.LENGTH_LONG)
.setGestureInsetBottomIgnored(true).show();
else
Log.unexpectedError(getParentFragmentManager(), ex);
@ -3627,7 +3627,7 @@ public class FragmentMessages extends FragmentBase
@Override
protected void onException(Bundle args, Throwable ex) {
if (ex instanceof IllegalArgumentException)
Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG)
Snackbar.make(view, new ThrowableWrapper(ex).getSafeMessage(), Snackbar.LENGTH_LONG)
.setGestureInsetBottomIgnored(true).show();
else
Log.unexpectedError(getParentFragmentManager(), ex);
@ -9830,7 +9830,7 @@ public class FragmentMessages extends FragmentBase
(ks != null && ks.getCertificateAlias(cert) != null ? " (Android)" : ""));
} catch (Throwable ex) {
Log.e(ex);
trace.add(ex.toString());
trace.add(new ThrowableWrapper(ex).toSafeString());
}
return trace;
}

@ -1308,7 +1308,7 @@ public class FragmentOptionsBackup extends FragmentBase implements SharedPrefere
ssb.setSpan(new ForegroundColorSpan(colorWarning), 0, ssb.length(), 0);
ssb.append("\n\n");
}
ssb.append(ex.toString());
ssb.append(new ThrowableWrapper(ex).toSafeString());
onProgress(ssb, null);
}
}
@ -1866,7 +1866,7 @@ public class FragmentOptionsBackup extends FragmentBase implements SharedPrefere
.setIcon(R.drawable.twotone_warning_24)
.setTitle(getString(R.string.title_advanced_cloud_invalid))
.setNegativeButton(android.R.string.cancel, null);
String message = ex.getMessage();
String message = new ThrowableWrapper(ex).getSafeMessage();
if (!TextUtils.isEmpty(message))
builder.setMessage(message);
builder.show();

@ -522,7 +522,7 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre
tm.checkServerTrusted(x509certs.toArray(new X509Certificate[0]), "UNKNOWN");
sb.append("Peer certificate trusted\n");
} catch (Throwable ex) {
sb.append(ex.toString()).append('\n');
sb.append(new ThrowableWrapper(ex).toSafeString()).append('\n');
}
}
} finally {

@ -736,7 +736,7 @@ public class FragmentOptionsEncryption extends FragmentBase
tvOpenPgpStatus.setText("Not connected");
else {
Log.e(ex);
tvOpenPgpStatus.setText(ex.toString());
tvOpenPgpStatus.setText(new ThrowableWrapper(ex).toSafeString());
}
}
}

@ -2427,7 +2427,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
@Override
protected void onException(Bundle args, Throwable ex) {
Log.w(ex);
tvSuffixes.setText(ex.toString());
tvSuffixes.setText(new ThrowableWrapper(ex).toSafeString());
}
}.execute(this, new Bundle(), "suffixes");
}
@ -2522,7 +2522,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
@Override
protected void onException(Bundle args, Throwable ex) {
Log.w(ex);
tvPermissions.setText(ex.toString());
tvPermissions.setText(new ThrowableWrapper(ex).toSafeString());
}
}.execute(this, new Bundle(), "permissions");
}

@ -758,7 +758,7 @@ public class FragmentPop extends FragmentBase {
@Override
protected void onException(Bundle args, Throwable ex) {
if (ex instanceof IllegalArgumentException)
Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG)
Snackbar.make(view, new ThrowableWrapper(ex).getSafeMessage(), Snackbar.LENGTH_LONG)
.setGestureInsetBottomIgnored(true).show();
else {
tvError.setText(Log.formatThrowable(ex, false));

@ -1596,7 +1596,7 @@ public class FragmentRule extends FragmentBase {
@Override
protected void onException(Bundle args, Throwable ex) {
if (ex instanceof IllegalArgumentException)
Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG)
Snackbar.make(view, new ThrowableWrapper(ex).getSafeMessage(), Snackbar.LENGTH_LONG)
.setGestureInsetBottomIgnored(true).show();
else
Log.unexpectedError(getParentFragmentManager(), ex);

@ -240,6 +240,7 @@ public class Fts4DbHelper extends SQLiteOpenHelper {
" args=" + TextUtils.join(", ", args) +
" query=" + query);
List<Long> result = new ArrayList<>();
// TODO CASA
try (Cursor cursor = DB.jni_safe_sqlite_query(db,
"message", new String[]{"rowid"},
select,

@ -240,6 +240,7 @@ public class Fts5DbHelper extends SQLiteOpenHelper {
" args=" + TextUtils.join(", ", args) +
" query=" + criteria.query);
List<Long> result = new ArrayList<>();
// TODO CASA
try (Cursor cursor = DB.jni_safe_sqlite_query(db,
"message", new String[]{"rowid"},
select,

@ -2139,7 +2139,7 @@ public class Helper {
try {
return view.getContext().getResources().getResourceEntryName(id);
} catch (Throwable ex) {
return ex.toString();
return new ThrowableWrapper(ex).toSafeString();
}
}
@ -2733,6 +2733,7 @@ public class Helper {
}
static void writeText(File file, String content) throws IOException {
// TODO CASA
try (FileOutputStream out = new FileOutputStream(file)) {
Log.write(out, content);
}

@ -428,7 +428,7 @@ public class HtmlHelper {
Log.e(ex);
Document document = Document.createShell("");
Element strong = document.createElement("strong");
strong.text(android.util.Log.getStackTraceString(ex));
strong.text(new ThrowableWrapper(ex).getSafeStackTraceString());
document.body().appendChild(strong);
return document;
}
@ -442,7 +442,7 @@ public class HtmlHelper {
Log.e(ex);
Document document = Document.createShell("");
Element strong = document.createElement("strong");
strong.text(android.util.Log.getStackTraceString(ex));
strong.text(new ThrowableWrapper(ex).getSafeStackTraceString());
document.body().appendChild(strong);
return document;
}

@ -1907,6 +1907,7 @@ public class Log {
draft.ui_seen = true;
draft.id = db.message().insertMessage(draft);
// TODO CASA
File file = draft.getFile(context);
Helper.writeText(file, body);
db.message().setMessageContent(draft.id, true, null, 0, null, null);
@ -3384,7 +3385,7 @@ public class Log {
}, 0);
sb.append(" bindable=").append(bindable);
} catch (Throwable ex) {
size += write(os, ex.toString());
size += write(os, ex.toString() + "\r\n");
}
sb.append("\r\n");

@ -5798,7 +5798,7 @@ public class MessageHelper {
}
} catch (Throwable ex) {
Log.e(ex);
report.append(TextUtils.htmlEncode(ex.toString()));
report.append(TextUtils.htmlEncode(new ThrowableWrapper(ex).toSafeString()));
}
report.append("</div>");
this.html = report.toString();

@ -293,7 +293,7 @@ public class ProtectedContent {
@Override
protected void onException(Bundle args, Throwable ex) {
tvError.setText(new ThrowableWrapper(ex).getSafeMessage());
tvErrorDetail.setText(ex.toString());
tvErrorDetail.setText(new ThrowableWrapper(ex).toSafeString());
tvError.setVisibility(View.VISIBLE);
tvErrorDetail.setVisibility(View.VISIBLE);
}

@ -490,7 +490,7 @@ public class ServiceSend extends ServiceBase implements SharedPreferences.OnShar
Intent intent = new Intent(this, ActivityError.class);
intent.setAction("535:" + identity.id);
intent.putExtra("title", ex.getMessage());
intent.putExtra("title", new ThrowableWrapper(ex).getSafeMessage());
intent.putExtra("message", Log.formatThrowable(ex, "\n", false));
intent.putExtra("provider", "outlookgraph");
intent.putExtra("account", identity.account);

Loading…
Cancel
Save