Skip to content

Commit

Permalink
allow cause when logging debug error
Browse files Browse the repository at this point in the history
  • Loading branch information
TrianguloY committed Jun 23, 2024
1 parent 9c17c93 commit baaf2e7
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,7 @@ private void restorePreferencesMatching(String fileName, Function<String, Boolea
default -> AndroidUtils.assertError("Unknown type: " + type);
}
} catch (JSONException e) {
AndroidUtils.assertError("Error when restoring key: " + key);
e.printStackTrace();
AndroidUtils.assertError("Error when restoring key: " + key, e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ public void onNewUrl(UrlData newUrlData) {
try {
module.onPrepareUrl(urlData);
} catch (Exception e) {
e.printStackTrace();
AndroidUtils.assertError("Exception in onPrepareUrl for module " + module.getClass().getName());
AndroidUtils.assertError("Exception in onPrepareUrl for module " + module.getClass().getName(), e);
}
}

Expand Down Expand Up @@ -122,8 +121,7 @@ public void onNewUrl(UrlData newUrlData) {
continue main_loop;
}
} catch (Exception e) {
e.printStackTrace();
AndroidUtils.assertError("Exception in onModifyUrl for module " + module.getClass().getName());
AndroidUtils.assertError("Exception in onModifyUrl for module " + module.getClass().getName(), e);
}
}

Expand All @@ -134,8 +132,7 @@ public void onNewUrl(UrlData newUrlData) {
try {
module.onDisplayUrl(urlData);
} catch (Exception e) {
e.printStackTrace();
AndroidUtils.assertError("Exception in onDisplayUrl for module " + module.getClass().getName());
AndroidUtils.assertError("Exception in onDisplayUrl for module " + module.getClass().getName(), e);
}
}

Expand All @@ -146,8 +143,7 @@ public void onNewUrl(UrlData newUrlData) {
try {
module.onFinishUrl(urlData);
} catch (Exception e) {
e.printStackTrace();
AndroidUtils.assertError("Exception in onFinishUrl for module " + module.getClass().getName());
AndroidUtils.assertError("Exception in onFinishUrl for module " + module.getClass().getName(), e);
}
}

Expand Down Expand Up @@ -312,8 +308,7 @@ private void initializeModule(AModuleData moduleData, boolean drawer) {
module.onInitialize(child);
} catch (Exception e) {
// can't add module
e.printStackTrace();
AndroidUtils.assertError("Exception in initializeModule for module " + moduleData.getId());
AndroidUtils.assertError("Exception in initializeModule for module " + moduleData.getId(), e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public static List<Pair<String, JSONObject>> getRules(Activity cntx) {
return rules;
} catch (JSONException e) {
// invalid catalog, return empty
AndroidUtils.assertError(e.getMessage());
AndroidUtils.assertError(e.getMessage(), e);
return Collections.emptyList();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,17 @@ static void setEnabled(View view, boolean enabled) {
view.setAlpha(enabled ? 1f : 0.35f);
}

/**
* In debug mode, throws an AssertionError, in production just logs it and continues.
*/
/** In debug mode, throws an AssertionError, in production just logs it and continues. */
static void assertError(String detailMessage) {
Log.d("ASSERT_ERROR", detailMessage);
assertError(detailMessage, null);
}

/** In debug mode, throws an AssertionError, in production just logs it and continues. */
static void assertError(String detailMessage, Throwable cause) {
Log.d("ASSERT_ERROR", detailMessage, cause);
if (BuildConfig.DEBUG) {
// in debug mode, throw exception
throw new AssertionError(detailMessage);
throw new AssertionError(detailMessage, cause);
}
// non-debug, just discard
}
Expand Down Expand Up @@ -172,8 +175,11 @@ static <V extends View> void toggleableListener(V view, JavaUtils.Consumer<V> to
static void longTapForDescription(View view) {
view.setOnLongClickListener(v -> {
var contentDescription = v.getContentDescription();
if (contentDescription == null) AndroidUtils.assertError("No content description for view " + view);
Toast.makeText(v.getContext(), contentDescription, Toast.LENGTH_SHORT).show();
if (contentDescription == null) {
AndroidUtils.assertError("No content description for view " + view);
} else {
Toast.makeText(v.getContext(), contentDescription, Toast.LENGTH_SHORT).show();
}
return true;
});
}
Expand Down

0 comments on commit baaf2e7

Please sign in to comment.