Skip to content

Commit 1f71b48

Browse files
committed
SLCORE-268 Make sure telemetry is completely silent, unless internal debug is enabled
1 parent de02698 commit 1f71b48

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

core/src/main/java/org/sonarsource/sonarlint/core/telemetry/TelemetryClient.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,19 @@ public TelemetryClient(TelemetryClientConfig clientConfig, String product, Strin
5757
void upload(TelemetryData data, boolean usesConnectedMode, boolean usesSonarCloud) {
5858
try {
5959
sendPost(httpFactory.buildClient(clientConfig), createPayload(data, usesConnectedMode, usesSonarCloud));
60-
} catch (Exception e) {
60+
} catch (Throwable catchEmAll) {
6161
if (SonarLintUtils.isInternalDebugEnabled()) {
62-
LOG.error("Failed to upload telemetry data", e);
62+
LOG.error("Failed to upload telemetry data", catchEmAll);
6363
}
6464
}
6565
}
6666

6767
void optOut(TelemetryData data, boolean usesConnectedMode, boolean usesSonarCloud) {
6868
try {
6969
sendDelete(httpFactory.buildClient(clientConfig), createPayload(data, usesConnectedMode, usesSonarCloud));
70-
} catch (Exception e) {
70+
} catch (Throwable catchEmAll) {
7171
if (SonarLintUtils.isInternalDebugEnabled()) {
72-
LOG.error("Failed to upload telemetry opt-out", e);
72+
LOG.error("Failed to upload telemetry opt-out", catchEmAll);
7373
}
7474
}
7575
}

core/src/test/java/org/sonarsource/sonarlint/core/telemetry/TelemetryClientTest.java

+7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
*/
2020
package org.sonarsource.sonarlint.core.telemetry;
2121

22+
import java.io.IOError;
2223
import org.junit.AfterClass;
2324
import org.junit.Before;
2425
import org.junit.Rule;
@@ -88,6 +89,12 @@ public void should_not_crash_when_cannot_opt_out() {
8889
client.optOut(new TelemetryData(), true, true);
8990
}
9091

92+
@Test
93+
public void should_not_crash_when_error_is_thrown() {
94+
when(http.post(any(PostRequest.class), anyString())).thenThrow(new IOError(new RuntimeException()));
95+
client.upload(new TelemetryData(), true, true);
96+
}
97+
9198
@Test
9299
public void failed_upload_should_log_if_debug() {
93100
env.set("SONARLINT_INTERNAL_DEBUG", "true");

0 commit comments

Comments
 (0)