diff --git a/core/src/main/java/org/sonarsource/sonarlint/core/telemetry/TelemetryClient.java b/core/src/main/java/org/sonarsource/sonarlint/core/telemetry/TelemetryClient.java index 560b8a0da6..2035027562 100644 --- a/core/src/main/java/org/sonarsource/sonarlint/core/telemetry/TelemetryClient.java +++ b/core/src/main/java/org/sonarsource/sonarlint/core/telemetry/TelemetryClient.java @@ -57,9 +57,9 @@ public TelemetryClient(TelemetryClientConfig clientConfig, String product, Strin void upload(TelemetryData data, boolean usesConnectedMode, boolean usesSonarCloud) { try { sendPost(httpFactory.buildClient(clientConfig), createPayload(data, usesConnectedMode, usesSonarCloud)); - } catch (Exception e) { + } catch (Throwable catchEmAll) { if (SonarLintUtils.isInternalDebugEnabled()) { - LOG.error("Failed to upload telemetry data", e); + LOG.error("Failed to upload telemetry data", catchEmAll); } } } @@ -67,9 +67,9 @@ void upload(TelemetryData data, boolean usesConnectedMode, boolean usesSonarClou void optOut(TelemetryData data, boolean usesConnectedMode, boolean usesSonarCloud) { try { sendDelete(httpFactory.buildClient(clientConfig), createPayload(data, usesConnectedMode, usesSonarCloud)); - } catch (Exception e) { + } catch (Throwable catchEmAll) { if (SonarLintUtils.isInternalDebugEnabled()) { - LOG.error("Failed to upload telemetry opt-out", e); + LOG.error("Failed to upload telemetry opt-out", catchEmAll); } } } diff --git a/core/src/test/java/org/sonarsource/sonarlint/core/telemetry/TelemetryClientTest.java b/core/src/test/java/org/sonarsource/sonarlint/core/telemetry/TelemetryClientTest.java index 12e4278527..251079f328 100644 --- a/core/src/test/java/org/sonarsource/sonarlint/core/telemetry/TelemetryClientTest.java +++ b/core/src/test/java/org/sonarsource/sonarlint/core/telemetry/TelemetryClientTest.java @@ -19,6 +19,7 @@ */ package org.sonarsource.sonarlint.core.telemetry; +import java.io.IOError; import org.junit.AfterClass; import org.junit.Before; import org.junit.Rule; @@ -88,6 +89,12 @@ public void should_not_crash_when_cannot_opt_out() { client.optOut(new TelemetryData(), true, true); } + @Test + public void should_not_crash_when_error_is_thrown() { + when(http.post(any(PostRequest.class), anyString())).thenThrow(new IOError(new RuntimeException())); + client.upload(new TelemetryData(), true, true); + } + @Test public void failed_upload_should_log_if_debug() { env.set("SONARLINT_INTERNAL_DEBUG", "true");