Skip to content

Commit

Permalink
SLCORE-268 Make sure telemetry is completely silent, unless internal …
Browse files Browse the repository at this point in the history
…debug is enabled
  • Loading branch information
jblievremont committed May 26, 2020
1 parent de02698 commit 1f71b48
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,19 @@ 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);
}
}
}

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);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 1f71b48

Please sign in to comment.