mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
optimize exception handling in logger
GitOrigin-RevId: dc29f629b89fcb3a28ec5d36279f3d8e111e1795
This commit is contained in:
committed by
intellij-monorepo-bot
parent
36c224779e
commit
69b2163ce5
+1
-1
@@ -35,7 +35,7 @@ class ExternalSystemRunConfigurationJavaExtensionTest : RunConfigurationJavaExte
|
||||
LoggedErrorProcessor.executeWith<RuntimeException>(object : LoggedErrorProcessor() {
|
||||
override fun processError(category: String, message: String, details: Array<out String>, t: Throwable?): Set<Action> =
|
||||
// don't fail this if `LOG.error()` was called for our exception somewhere
|
||||
if (t is FakeExecutionException) EnumSet.noneOf(Action::class.java) else EnumSet.allOf(Action::class.java)
|
||||
if (t is FakeExecutionException) Action.NONE else Action.ALL
|
||||
}) {
|
||||
runInEdtAndWait {
|
||||
ExecutionEnvironmentBuilder.create(DefaultRunExecutor.getRunExecutorInstance(), configuration).buildAndExecute()
|
||||
|
||||
+2
-2
@@ -872,8 +872,8 @@ class ExternalSystemStorageTest {
|
||||
private fun suppressLogs(action: () -> Unit) {
|
||||
LoggedErrorProcessor.executeWith<RuntimeException>(object : LoggedErrorProcessor() {
|
||||
override fun processError(category: String, message: String, details: Array<out String>, t: Throwable?): Set<Action> =
|
||||
if (message.contains("Trying to load multiple modules with the same name.")) EnumSet.noneOf(Action::class.java)
|
||||
else EnumSet.allOf(Action::class.java)
|
||||
if (message.contains("Trying to load multiple modules with the same name.")) Action.NONE
|
||||
else Action.ALL
|
||||
}) {
|
||||
action()
|
||||
}
|
||||
|
||||
+1
-1
@@ -47,7 +47,7 @@ class PooledCoroutineContextTest : UsefulTestCase() {
|
||||
LoggedErrorProcessor.executeWith<RuntimeException>(object : LoggedErrorProcessor() {
|
||||
override fun processError(category: String, message: String, details: Array<out String>, t: Throwable?): MutableSet<Action> {
|
||||
throwable = t
|
||||
return EnumSet.noneOf(Action::class.java)
|
||||
return Action.NONE
|
||||
}
|
||||
}, block)
|
||||
return throwable
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ public class BadActionShortcutCheckTest extends LightPlatformTestCase {
|
||||
protected void runTestRunnable(@NotNull ThrowableRunnable<Throwable> testRunnable) throws Throwable {
|
||||
LoggedErrorProcessor.executeWith(new LoggedErrorProcessor() {
|
||||
@Override
|
||||
public boolean processWarn(@NotNull String category, String message, Throwable t) {
|
||||
public boolean processWarn(@NotNull String category, @NotNull String message, Throwable t) {
|
||||
myLoggedWarnings.add(message);
|
||||
return super.processWarn(category, message, t);
|
||||
}
|
||||
|
||||
+2
-3
@@ -38,7 +38,6 @@ import org.jetbrains.concurrency.Promise;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.*;
|
||||
@@ -456,10 +455,10 @@ public class NonBlockingReadActionTest extends LightPlatformTestCase {
|
||||
AtomicReference<Throwable> loggedError = new AtomicReference<>();
|
||||
LoggedErrorProcessor.executeWith(new LoggedErrorProcessor() {
|
||||
@Override
|
||||
public Set<Action> processError(@NotNull String category, @NotNull String message, String @NotNull [] details, @Nullable Throwable t) {
|
||||
public @NotNull Set<Action> processError(@NotNull String category, @NotNull String message, String @NotNull [] details, @Nullable Throwable t) {
|
||||
assertNotNull(t);
|
||||
loggedError.set(t);
|
||||
return EnumSet.noneOf(Action.class);
|
||||
return Action.NONE;
|
||||
}
|
||||
}, ()->runnable.accept(loggedError));
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ fun loggedError(canThrow: Semaphore): Throwable {
|
||||
override fun processError(category: String, message: String, details: Array<out String>, t: Throwable?): Set<Action> {
|
||||
throwable = t!!
|
||||
gotIt.up()
|
||||
return EnumSet.noneOf(Action::class.java)
|
||||
return Action.NONE
|
||||
}
|
||||
}) {
|
||||
canThrow.up()
|
||||
|
||||
+1
-1
@@ -206,7 +206,7 @@ public class PersistentFsTest extends BareTestFixtureTestCase {
|
||||
int[] logCount = {0};
|
||||
LoggedErrorProcessor.executeWith(new LoggedErrorProcessor() {
|
||||
@Override
|
||||
public boolean processWarn(@NotNull String category, String message, Throwable t) {
|
||||
public boolean processWarn(@NotNull String category, @NotNull String message, Throwable t) {
|
||||
if (message.contains(jarFile.getName())) logCount[0]++;
|
||||
return super.processWarn(category, message, t);
|
||||
}
|
||||
|
||||
@@ -359,7 +359,7 @@ class AsyncPromiseTest {
|
||||
LoggedErrorProcessor.executeWith<RuntimeException>(object : LoggedErrorProcessor() {
|
||||
override fun processError(category: String, message: String, details: Array<out String>, t: Throwable?): Set<Action> {
|
||||
loggedError.set(true)
|
||||
return EnumSet.noneOf(Action::class.java)
|
||||
return Action.NONE
|
||||
}
|
||||
}) {
|
||||
val promise = ReadAction.nonBlocking {
|
||||
|
||||
+10
-5
@@ -39,7 +39,7 @@ public class LoggedErrorProcessor {
|
||||
AtomicReference<Throwable> error = new AtomicReference<>();
|
||||
executeWith(new LoggedErrorProcessor() {
|
||||
@Override
|
||||
public boolean processError(@NotNull String category, String message, Throwable t, String @NotNull [] details) {
|
||||
public boolean processError(@NotNull String category, @NotNull String message, Throwable t, String @NotNull [] details) {
|
||||
Assert.assertNotNull("Unexpected error without Throwable: " + message, t);
|
||||
if (!error.compareAndSet(null, t)) {
|
||||
Assert.fail("Multiple errors were reported: " + error.get().getMessage() + " and " + t.getMessage());
|
||||
@@ -58,23 +58,28 @@ public class LoggedErrorProcessor {
|
||||
*
|
||||
* @see TestLoggerFactory.TestLogger#warn(String, Throwable)
|
||||
*/
|
||||
public boolean processWarn(@NotNull String category, String message, Throwable t) {
|
||||
public boolean processWarn(@NotNull String category, @NotNull String message, @Nullable Throwable t) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public enum Action {LOG, STDERR, RETHROW}
|
||||
public enum Action {
|
||||
LOG, STDERR, RETHROW;
|
||||
public static final EnumSet<Action> ALL = EnumSet.allOf(Action.class);
|
||||
public static final EnumSet<Action> NONE = EnumSet.noneOf(Action.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a set of actions to be performed by {@link TestLoggerFactory.TestLogger#error(String, Throwable, String...)} on the given log event.
|
||||
*/
|
||||
@NotNull
|
||||
public Set<Action> processError(@NotNull String category, @NotNull String message, String @NotNull [] details, @Nullable Throwable t) {
|
||||
var process = processError(category, message, t, details);
|
||||
return process ? EnumSet.allOf(Action.class) : EnumSet.noneOf(Action.class);
|
||||
return process ? Action.ALL : Action.NONE;
|
||||
}
|
||||
|
||||
/** @deprecated use/override {@link #processError(String, String, String[], Throwable)} instead */
|
||||
@Deprecated(forRemoval = true)
|
||||
public boolean processError(@NotNull String category, String message, Throwable t, String @NotNull [] details) {
|
||||
public boolean processError(@NotNull String category, @NotNull String message, @Nullable Throwable t, String @NotNull [] details) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -88,7 +88,7 @@ class StringTemplateExpressionManipulatorTest : KotlinLightCodeInsightFixtureTes
|
||||
private fun suppressFallingOnLogError(call: () -> Unit) {
|
||||
LoggedErrorProcessor.executeWith<RuntimeException>(object : LoggedErrorProcessor() {
|
||||
override fun processError(category: String, message: String, details: Array<out String>, t: Throwable?): Set<Action> =
|
||||
EnumSet.noneOf(Action::class.java)
|
||||
Action.NONE
|
||||
}) {
|
||||
call()
|
||||
}
|
||||
|
||||
+1
-1
@@ -45,7 +45,7 @@ public abstract class MavenBuildToolLogTestUtils extends LightIdeaTestCase {
|
||||
public static void failOnWarns(ThrowableRunnable<Throwable> runnable) throws Throwable {
|
||||
LoggedErrorProcessor.executeWith(new LoggedErrorProcessor() {
|
||||
@Override
|
||||
public boolean processWarn(@NotNull String category, String message, Throwable t) {
|
||||
public boolean processWarn(@NotNull String category, @NotNull String message, Throwable t) {
|
||||
fail(message + t);
|
||||
return false;
|
||||
}
|
||||
|
||||
+1
-1
@@ -85,7 +85,7 @@ class InvalidEnvironmentImportingTest : MavenMultiVersionImportingTestCase() {
|
||||
|
||||
private fun loggedErrorProcessor(search: String) = object : LoggedErrorProcessor() {
|
||||
override fun processError(category: String, message: String, details: Array<out String>, t: Throwable?): Set<Action> =
|
||||
if (message.contains(search)) EnumSet.noneOf(Action::class.java) else EnumSet.allOf(Action::class.java)
|
||||
if (message.contains(search)) Action.NONE else Action.ALL
|
||||
}
|
||||
|
||||
private fun assertEvent(description: String = "Asserted", predicate: (BuildEvent) -> Boolean) {
|
||||
|
||||
@@ -153,11 +153,11 @@ public abstract class MavenTestCase extends UsefulTestCase {
|
||||
protected void runBare(@NotNull ThrowableRunnable<Throwable> testRunnable) throws Throwable {
|
||||
LoggedErrorProcessor.executeWith(new LoggedErrorProcessor() {
|
||||
@Override
|
||||
public Set<Action> processError(@NotNull String category, @NotNull String message, String @NotNull [] details, @Nullable Throwable t) {
|
||||
public @NotNull Set<Action> processError(@NotNull String category, @NotNull String message, String @NotNull [] details, @Nullable Throwable t) {
|
||||
boolean intercept = t != null && (
|
||||
StringUtil.notNullize(t.getMessage()).contains("The network name cannot be found") && message.contains("Couldn't read shelf information") ||
|
||||
"JDK annotations not found".equals(t.getMessage()) && "#com.intellij.openapi.projectRoots.impl.JavaSdkImpl".equals(category));
|
||||
return intercept ? EnumSet.noneOf(Action.class) : EnumSet.allOf(Action.class);
|
||||
return intercept ? Action.NONE : Action.ALL;
|
||||
}
|
||||
}, () -> super.runBare(testRunnable));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user