Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add additional logs when embedded Node.js is not available #4618

Merged
merged 3 commits into from Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -19,6 +19,8 @@
*/
package org.sonar.plugins.javascript.bridge;

import static org.sonar.plugins.javascript.nodejs.NodeCommandBuilderImpl.NODE_EXECUTABLE_PROPERTY;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -87,7 +89,9 @@ public void execute(SensorContext context) {
throw new IllegalStateException(
"Error while running Node.js. A supported version of Node.js is required for running the analysis of " +
this.lang +
" files. Please make sure a supported version of Node.js is available in the PATH. Alternatively, you can exclude " +
" files. Please make sure a supported version of Node.js is available in the PATH or an executable path is provided via '" +
NODE_EXECUTABLE_PROPERTY +
"' property. Alternatively, you can exclude " +
this.lang +
" files from your analysis using the 'sonar.exclusions' configuration property. " +
"See the docs for configuring the analysis environment: https://docs.sonarsource.com/sonarqube/latest/analyzing-source-code/languages/javascript-typescript-css/",
Expand Down
Expand Up @@ -168,6 +168,9 @@ public void deploy() throws IOException {
platform
);
if (platform == UNSUPPORTED) {
LOG.debug(
"Your platform is not supported for embedded Node.js. Falling back to host Node.js."
);
return;
}
try {
Expand Down
Expand Up @@ -48,7 +48,7 @@ public class NodeCommandBuilderImpl implements NodeCommandBuilder {
private static final String NODE_EXECUTABLE_DEFAULT_MACOS =
"package/node_modules/run-node/run-node";

private static final String NODE_EXECUTABLE_PROPERTY = "sonar.nodejs.executable";
public static final String NODE_EXECUTABLE_PROPERTY = "sonar.nodejs.executable";
private static final String NODE_FORCE_HOST_PROPERTY = "sonar.nodejs.forceHost";

private static final Pattern NODEJS_VERSION_PATTERN = Pattern.compile(
Expand Down
Expand Up @@ -283,7 +283,7 @@ void failed_server_should_log_error_with_css() throws IOException {
assertThatThrownBy(() -> sensor.execute(context))
.isInstanceOf(IllegalStateException.class)
.hasMessage(
"Error while running Node.js. A supported version of Node.js is required for running the analysis of CSS files. Please make sure a supported version of Node.js is available in the PATH. Alternatively, you can exclude CSS files from your analysis using the 'sonar.exclusions' configuration property. See the docs for configuring the analysis environment: https://docs.sonarsource.com/sonarqube/latest/analyzing-source-code/languages/javascript-typescript-css/"
"Error while running Node.js. A supported version of Node.js is required for running the analysis of CSS files. Please make sure a supported version of Node.js is available in the PATH or an executable path is provided via 'sonar.nodejs.executable' property. Alternatively, you can exclude CSS files from your analysis using the 'sonar.exclusions' configuration property. See the docs for configuring the analysis environment: https://docs.sonarsource.com/sonarqube/latest/analyzing-source-code/languages/javascript-typescript-css/"
);
assertThat(logTester.logs(LoggerLevel.ERROR)).contains("Exception Message");
}
Expand Down
Expand Up @@ -149,6 +149,19 @@ void test_unsupported_archs() {
assertThat(Platform.detect(macos)).isEqualTo(UNSUPPORTED);
}

@Test
void should_log_if_platform_unsupported() throws Exception {
logTester.setLevel(Level.DEBUG);
var en = new EmbeddedNode(mock(ProcessWrapper.class), createUnsupportedEnvironment());
en.deploy();
assertThat(logTester.logs())
.anyMatch(l ->
l.startsWith(
"Your platform is not supported for embedded Node.js. Falling back to host Node.js."
)
);
}

@Test
void should_fail_gracefully() throws Exception {
ProcessWrapper processWrapper = mock(ProcessWrapper.class);
Expand Down
Expand Up @@ -108,7 +108,7 @@ class JavaScriptEslintBasedSensorTest {
private SensorContextTester context;

private String nodeExceptionMessage =
"Error while running Node.js. A supported version of Node.js is required for running the analysis of JS/TS files. Please make sure a supported version of Node.js is available in the PATH. Alternatively, you can exclude JS/TS files from your analysis using the 'sonar.exclusions' configuration property. See the docs for configuring the analysis environment: https://docs.sonarsource.com/sonarqube/latest/analyzing-source-code/languages/javascript-typescript-css/";
"Error while running Node.js. A supported version of Node.js is required for running the analysis of JS/TS files. Please make sure a supported version of Node.js is available in the PATH or an executable path is provided via 'sonar.nodejs.executable' property. Alternatively, you can exclude JS/TS files from your analysis using the 'sonar.exclusions' configuration property. See the docs for configuring the analysis environment: https://docs.sonarsource.com/sonarqube/latest/analyzing-source-code/languages/javascript-typescript-css/";

@TempDir
Path workDir;
Expand Down