0
0
mirror of https://github.com/TrianguloY/UrlChecker.git synced 2024-09-19 20:02:16 +02:00

allow cause when logging debug error

This commit is contained in:
TrianguloY 2024-06-22 21:01:25 +02:00
parent 9c17c933a0
commit baaf2e7431
4 changed files with 20 additions and 20 deletions

View File

@ -338,8 +338,7 @@ public class BackupActivity extends Activity {
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);
}
}

View File

@ -92,8 +92,7 @@ public class MainDialog extends Activity {
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);
}
}
@ -122,8 +121,7 @@ public class MainDialog extends Activity {
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);
}
}
@ -134,8 +132,7 @@ public class MainDialog extends Activity {
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);
}
}
@ -146,8 +143,7 @@ public class MainDialog extends Activity {
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);
}
}
@ -312,8 +308,7 @@ public class MainDialog extends Activity {
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);
}
}

View File

@ -114,7 +114,7 @@ public class ClearUrlCatalog {
return rules;
} catch (JSONException e) {
// invalid catalog, return empty
AndroidUtils.assertError(e.getMessage());
AndroidUtils.assertError(e.getMessage(), e);
return Collections.emptyList();
}
}

View File

@ -43,14 +43,17 @@ public interface AndroidUtils {
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
}
@ -172,8 +175,11 @@ public interface AndroidUtils {
static void longTapForDescription(View view) {
view.setOnLongClickListener(v -> {
var contentDescription = v.getContentDescription();
if (contentDescription == null) AndroidUtils.assertError("No content description for view " + view);
if (contentDescription == null) {
AndroidUtils.assertError("No content description for view " + view);
} else {
Toast.makeText(v.getContext(), contentDescription, Toast.LENGTH_SHORT).show();
}
return true;
});
}