From 51599b3cae58b1bbc9f610b0aefbe484d3afe432 Mon Sep 17 00:00:00 2001 From: Arthur Baars Date: Mon, 6 Mar 2023 16:36:28 +0100 Subject: [PATCH] Address review comments --- .../com/semmle/js/extractor/AutoBuild.java | 20 ++++++++++++------- .../extractor/test/NodeJSDetectorTests.java | 2 -- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/javascript/extractor/src/com/semmle/js/extractor/AutoBuild.java b/javascript/extractor/src/com/semmle/js/extractor/AutoBuild.java index cae28587723..710dbe94fc7 100644 --- a/javascript/extractor/src/com/semmle/js/extractor/AutoBuild.java +++ b/javascript/extractor/src/com/semmle/js/extractor/AutoBuild.java @@ -8,10 +8,12 @@ import java.lang.ProcessBuilder.Redirect; import java.net.URI; import java.net.URISyntaxException; import java.nio.charset.StandardCharsets; +import java.nio.file.DirectoryNotEmptyException; import java.nio.file.FileVisitResult; import java.nio.file.FileVisitor; import java.nio.file.Files; import java.nio.file.InvalidPathException; +import java.nio.file.NoSuchFileException; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.SimpleFileVisitor; @@ -487,10 +489,13 @@ public class AutoBuild { } // ensuring that the finalize steps detects that no code was seen. Path srcFolder = Paths.get(EnvironmentVariables.getWipDatabase(), "src"); - // check that the srcFolder is empty - if (Files.list(srcFolder).count() == 0) { + try { // Non-recursive delete because "src/" should be empty. FileUtil8.delete(srcFolder); + } catch (NoSuchFileException e) { + Exceptions.ignore(e, "the directory did not exist"); + } catch (DirectoryNotEmptyException e) { + Exceptions.ignore(e, "just leave the directory if it is not empty"); } return 0; } @@ -1230,11 +1235,12 @@ protected DependencyInstallationResult preparePackagesAndDependencies(Set if (!extractor.getConfig().isExterns() && (loc == null || loc.getLinesOfCode() != 0)) seenCode = true; if (!extractor.getConfig().isExterns()) seenFiles = true; for (ParseError err : loc.getParseErrors()) { - String msg = "A parse error occurred: " + err.getMessage() + ". Check the syntax of the file. If the file is invalid, correct the error or exclude the file from analysis."; + String msg = "A parse error occurred: " + StringUtil.escapeMarkdown(err.getMessage()) + + ". Check the syntax of the file. If the file is invalid, correct the error or exclude the file from analysis."; // file, relative to the source root - String relativeFilePath = file.toString(); - if (relativeFilePath.startsWith(LGTM_SRC.toString())) { - relativeFilePath = relativeFilePath.substring(LGTM_SRC.toString().length() + 1); + String relativeFilePath = null; + if (file.startsWith(LGTM_SRC)) { + relativeFilePath = file.subpath(LGTM_SRC.getNameCount(), file.getNameCount()).toString(); } DiagnosticLocation diagLoc = DiagnosticLocation.builder() .setFile(relativeFilePath) @@ -1255,7 +1261,7 @@ protected DependencyInstallationResult preparePackagesAndDependencies(Set try { writeDiagnostics("Internal error: " + t, JSDiagnosticKind.INTERNAL_ERROR); } catch (IOException ignored) { - // ignore - we are already crashing + Exceptions.ignore(ignored, "we are already crashing"); } System.exit(1); } diff --git a/javascript/extractor/src/com/semmle/js/extractor/test/NodeJSDetectorTests.java b/javascript/extractor/src/com/semmle/js/extractor/test/NodeJSDetectorTests.java index fe709033cbe..14d5b323e7c 100644 --- a/javascript/extractor/src/com/semmle/js/extractor/test/NodeJSDetectorTests.java +++ b/javascript/extractor/src/com/semmle/js/extractor/test/NodeJSDetectorTests.java @@ -1,7 +1,5 @@ package com.semmle.js.extractor.test; -import java.io.File; - import com.semmle.js.ast.Node; import com.semmle.js.extractor.ExtractionMetrics; import com.semmle.js.extractor.ExtractorConfig;