Skip to content

Commit

Permalink
SLE-1065: Overhaul error notification
Browse files Browse the repository at this point in the history
When user decide to ignore an error, also ignore "similar" errors.
Also give the user the opportunity to not show any error notifications again.
  • Loading branch information
thahnen committed Feb 7, 2025
1 parent 0b81de6 commit 17f045d
Show file tree
Hide file tree
Showing 12 changed files with 196 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.eclipse.reddeer.common.wait.WaitWhile;
import org.eclipse.reddeer.eclipse.ui.perspectives.JavaPerspective;
import org.eclipse.reddeer.swt.impl.link.DefaultLink;
import org.eclipse.reddeer.swt.impl.shell.DefaultShell;
import org.eclipse.reddeer.workbench.core.condition.JobIsRunning;
import org.eclipse.reddeer.workbench.ui.dialogs.WorkbenchPreferenceDialog;
import org.junit.AfterClass;
Expand Down Expand Up @@ -118,10 +117,6 @@ public static void cleanupOrchestrator() {

// Because we only use CDT in here, we switch back for other tests to not get confused!
new JavaPerspective().open();

// Because we might kill the connection in the middle of synchronization a 401 can happen, in
// this case an error will throw (correctly)
shellByName("SonarQube for Eclipse - An error occurred").ifPresent(DefaultShell::close);
}

@Before
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public static final void setUpBeforeClass() {
System.setProperty("sonarlint.internal.ignoreMissingFeature", "true");
System.setProperty("sonarlint.internal.ignoreNoAutomaticBuildWarning", "true");
System.setProperty("sonarlint.internal.hideVersionHint", "true");
System.setProperty("sonarlint.internal.noErrorNotifcation", "true");
}

@AfterClass
Expand All @@ -126,6 +127,7 @@ public static final void cleanupAfterClass() {
System.clearProperty("sonarlint.internal.ignoreMissingFeature");
System.clearProperty("sonarlint.internal.ignoreNoAutomaticBuildWarning");
System.clearProperty("sonarlint.internal.hideVersionHint");
System.clearProperty("sonarlint.internal.noErrorNotifcation");

// remove warning about soon unsupported version (there can be multiple)
if ("oldest".equals(System.getProperty("target.platform"))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
package org.sonarlint.eclipse.core.internal.jobs;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.CountDownLatch;
Expand Down Expand Up @@ -106,15 +108,36 @@ public void error(String msg, boolean fromAnalyzer) {
System.err.println("ERROR " + msg);
}

@Override
public void error(@Nullable String msg, Throwable t, boolean fromAnalyzer) {
var stack = new StringWriter();
t.printStackTrace(new PrintWriter(stack));
error(msg, fromAnalyzer);
error(stack.toString(), fromAnalyzer);
}

@Override
public void debug(String msg, boolean fromAnalyzer) {
System.out.println("DEBUG " + msg);
}

@Override
public void debug(@Nullable String msg, Throwable t, boolean fromAnalyzer) {
var stack = new StringWriter();
t.printStackTrace(new PrintWriter(stack));
debug(msg, fromAnalyzer);
debug(stack.toString(), fromAnalyzer);
}

@Override
public void traceIdeMessage(@Nullable String msg) {
// INFO: We ignore Eclipse-specific tracing in UTs
}

@Override
public void traceIdeMessage(@Nullable String msg, Throwable t) {
// INFO: We ignore Eclipse-specific tracing in UTs
}
};
SonarLintLogger.get().addLogListener(listener);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
package org.sonarlint.eclipse.core.internal.resources;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.resources.ProjectScope;
Expand Down Expand Up @@ -52,14 +54,33 @@ public void error(String msg, boolean fromAnalyzer) {
errors.add(msg);
}

@Override
public void error(@Nullable String msg, Throwable t, boolean fromAnalyzer) {
var stack = new StringWriter();
t.printStackTrace(new PrintWriter(stack));
error(msg, fromAnalyzer);
error(stack.toString(), fromAnalyzer);
}

@Override
public void debug(String msg, boolean fromAnalyzer) {
// We ignore debug messages in UTs
}

@Override
public void debug(@Nullable String msg, Throwable t, boolean fromAnalyzer) {
// We ignore debug messages in UTs
}

@Override
public void traceIdeMessage(@Nullable String msg) {
// INFO: We ignore Eclipse-specific tracing in UTs
}

@Override
public void traceIdeMessage(@Nullable String msg, Throwable t) {
// INFO: We ignore Eclipse-specific tracing in UTs
}
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*/
package org.sonarlint.eclipse.core.internal.tracking;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -72,6 +74,7 @@ public static void prepare() throws Exception {
SonarLintLogger.get().addLogListener(new LogListener() {
@Override
public void info(String msg, boolean fromAnalyzer) {
// We ignore info messages in UTs
}

@Override
Expand All @@ -83,14 +86,33 @@ public void error(String msg, boolean fromAnalyzer) {
}
}

@Override
public void error(@Nullable String msg, Throwable t, boolean fromAnalyzer) {
var stack = new StringWriter();
t.printStackTrace(new PrintWriter(stack));
error(msg, fromAnalyzer);
error(stack.toString(), fromAnalyzer);
}

@Override
public void debug(String msg, boolean fromAnalyzer) {
// We ignore debug messages in UTs
}

@Override
public void debug(@Nullable String msg, Throwable t, boolean fromAnalyzer) {
// We ignore debug messages in UTs
}

@Override
public void traceIdeMessage(@Nullable String msg) {
// INFO: We ignore Eclipse-specific tracing in UTs
}

@Override
public void traceIdeMessage(@Nullable String msg, Throwable t) {
// INFO: We ignore Eclipse-specific tracing in UTs
}
});
project = importEclipseProject("reference");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*/
package org.sonarlint.eclipse.core.internal.utils;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -48,21 +50,41 @@ public static void setSystemProperties() {
SonarLintLogger.get().addLogListener(new LogListener() {
@Override
public void info(@Nullable String msg, boolean fromAnalyzer) {
// We ignore info messages in UTs
}

@Override
public void error(@Nullable String msg, boolean fromAnalyzer) {
errors.add(msg);
}

@Override
public void error(@Nullable String msg, Throwable t, boolean fromAnalyzer) {
var stack = new StringWriter();
t.printStackTrace(new PrintWriter(stack));
error(msg, fromAnalyzer);
error(stack.toString(), fromAnalyzer);
}

@Override
public void debug(@Nullable String msg, boolean fromAnalyzer) {
// We ignore debug messages in UTs
}

@Override
public void debug(@Nullable String msg, Throwable t, boolean fromAnalyzer) {
// We ignore debug messages in UTs
}

@Override
public void traceIdeMessage(@Nullable String msg) {
// INFO: We ignore Eclipse-specific tracing in UTs
}

@Override
public void traceIdeMessage(@Nullable String msg, Throwable t) {
// INFO: We ignore Eclipse-specific tracing in UTs
}
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
*/
package org.sonarlint.eclipse.core;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.jdt.annotation.Nullable;
Expand Down Expand Up @@ -60,10 +58,7 @@ public void analyzerError(String msg) {

public void error(String msg, Throwable t) {
for (var listener : logListeners) {
listener.error(msg, false);
var stack = new StringWriter();
t.printStackTrace(new PrintWriter(stack));
listener.error(stack.toString(), false);
listener.error(msg, t, false);
}
}

Expand Down Expand Up @@ -93,10 +88,7 @@ public void analyzerDebug(String msg) {

public void debug(String msg, Throwable t) {
for (var listener : logListeners) {
listener.debug(msg, false);
var stack = new StringWriter();
t.printStackTrace(new PrintWriter(stack));
listener.debug(stack.toString(), false);
listener.debug(msg, t, false);
}
}

Expand All @@ -108,10 +100,7 @@ public void traceIdeMessage(String msg) {

public void traceIdeMessage(String msg, Throwable t) {
for (var listener : logListeners) {
listener.traceIdeMessage(msg);
var stack = new StringWriter();
t.printStackTrace(new PrintWriter(stack));
listener.traceIdeMessage(stack.toString());
listener.traceIdeMessage(msg, t);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,18 @@ public interface LogListener {

void error(@Nullable String msg, boolean fromAnalyzer);

void error(@Nullable String msg, Throwable t, boolean fromAnalyzer);

void debug(@Nullable String msg, boolean fromAnalyzer);

void debug(@Nullable String msg, Throwable t, boolean fromAnalyzer);

/**
* This should only be used for IDE-specific logging and is not intended for tracing messages from SLCORE as these
* ones are handled like debug messages. IDE-specific logging is something like adaptations, interaction with an
* extension point, ...
*/
void traceIdeMessage(@Nullable String msg);

void traceIdeMessage(@Nullable String msg, Throwable t);
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public class SonarLintGlobalConfiguration {
private static final String PREF_SOON_UNSUPPORTED_CONNECTIONS = "soonUnsupportedSonarQubeConnections"; //$NON-NLS-1$
private static final String PREF_NO_AUTOMATIC_BUILD_WARNING = "noAutomaticBuildWarning"; //$NON-NLS-1$
private static final String PREF_NO_CONNECTION_SUGGESTIONS = "NoConnectionSuggestions"; //$NON-NLS-1$
private static final String PREF_NO_ERROR_NOTIFICATION = "noErrorNotification"; //$NON-NLS-1$

// When SonarLint is updated (or installed), we inform the user by opening the "Welcome" page and show a notification
// about the new Release Notes. When a new version is available, we will inform the user as well (but only once a
Expand Down Expand Up @@ -450,6 +451,18 @@ public static void setNoAutomaticBuildWarning() {
setPreferenceBoolean(getWorkspaceLevelPreferenceNode(), PREF_NO_AUTOMATIC_BUILD_WARNING, true);
}

public static boolean noErrorNotifcation() {
// For integration tests we need to disable the notifications
var property = System.getProperty("sonarlint.internal.noErrorNotifcation");
return property == null || property.isBlank()
? getPreferenceBoolean(PREF_NO_ERROR_NOTIFICATION)
: Boolean.parseBoolean(property);
}

public static void setNoErrorNotifcation() {
setPreferenceBoolean(getWorkspaceLevelPreferenceNode(), PREF_NO_ERROR_NOTIFICATION, true);
}

public static boolean noConnectionSuggestions() {
return getPreferenceBoolean(PREF_NO_CONNECTION_SUGGESTIONS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,20 +112,41 @@ public void error(@Nullable String msg, boolean fromAnalyzer) {
}
}

@Override
public void error(@Nullable String msg, Throwable t, boolean fromAnalyzer) {
if (PlatformUI.isWorkbenchRunning()) {
doAsyncInUiThread(() -> getSonarConsole().error(msg, t, fromAnalyzer));
}
}

@Override
public void debug(@Nullable String msg, boolean fromAnalyzer) {
if (PlatformUI.isWorkbenchRunning()) {
doAsyncInUiThread(() -> getSonarConsole().debug(msg, fromAnalyzer));
}
}

@Override
public void debug(@Nullable String msg, Throwable t, boolean fromAnalyzer) {
if (PlatformUI.isWorkbenchRunning()) {
doAsyncInUiThread(() -> getSonarConsole().debug(msg, t, fromAnalyzer));
}
}

@Override
public void traceIdeMessage(@Nullable String msg) {
if (PlatformUI.isWorkbenchRunning()) {
doAsyncInUiThread(() -> getSonarConsole().traceIdeMessage(msg));
}
}

@Override
public void traceIdeMessage(@Nullable String msg, Throwable t) {
if (PlatformUI.isWorkbenchRunning()) {
doAsyncInUiThread(() -> getSonarConsole().traceIdeMessage(msg, t));
}
}

void doAsyncInUiThread(Runnable task) {
logConsumer.submit(() -> Display.getDefault().syncExec(task));
}
Expand Down
Loading

0 comments on commit 17f045d

Please sign in to comment.