From 04b407fcbb9835a1228eb130c3edce5e61341510 Mon Sep 17 00:00:00 2001 From: Eric Giffon Date: Tue, 7 Feb 2023 15:17:32 +0100 Subject: [PATCH] SONAR-18242 Clarify error message when creating new project without permissions during scan --- .../org/sonar/scanner/bootstrap/DefaultScannerWsClient.java | 3 ++- .../sonar/scanner/bootstrap/DefaultScannerWsClientTest.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/DefaultScannerWsClient.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/DefaultScannerWsClient.java index 3c5b422c77e..a53e81dc407 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/DefaultScannerWsClient.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/DefaultScannerWsClient.java @@ -113,7 +113,8 @@ public class DefaultScannerWsClient implements ScannerWsClient { + "Please provide a user token in %s or other credentials in %s and %s.", CoreProperties.LOGIN, CoreProperties.LOGIN, CoreProperties.PASSWORD)); } if (code == HTTP_FORBIDDEN) { - throw MessageException.of("You're not authorized to run analysis. Please contact the project administrator."); + throw MessageException.of("You're not authorized to analyze this project or the project doesn't exist on SonarQube" + + " and you're not authorized to create it. Please contact an administrator."); } if (code == HTTP_BAD_REQUEST) { String jsonMsg = tryParseAsJsonError(response.content()); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/DefaultScannerWsClientTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/DefaultScannerWsClientTest.java index df4aaffb90d..cf2c26e7a15 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/DefaultScannerWsClientTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/DefaultScannerWsClientTest.java @@ -127,7 +127,7 @@ public class DefaultScannerWsClientTest { assertThatThrownBy(() -> new DefaultScannerWsClient(wsClient, true, new GlobalAnalysisMode(new ScannerProperties(Collections.emptyMap())), analysisWarnings).call(request)) .isInstanceOf(MessageException.class) - .hasMessage("You're not authorized to run analysis. Please contact the project administrator."); + .hasMessage("You're not authorized to analyze this project or the project doesn't exist on SonarQube and you're not authorized to create it. Please contact an administrator."); } @Test -- 2.39.5