Skip to content

Commit 51599b3

Browse files
committed
Address review comments
1 parent fc9e632 commit 51599b3

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

javascript/extractor/src/com/semmle/js/extractor/AutoBuild.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
import java.net.URI;
99
import java.net.URISyntaxException;
1010
import java.nio.charset.StandardCharsets;
11+
import java.nio.file.DirectoryNotEmptyException;
1112
import java.nio.file.FileVisitResult;
1213
import java.nio.file.FileVisitor;
1314
import java.nio.file.Files;
1415
import java.nio.file.InvalidPathException;
16+
import java.nio.file.NoSuchFileException;
1517
import java.nio.file.Path;
1618
import java.nio.file.Paths;
1719
import java.nio.file.SimpleFileVisitor;
@@ -487,10 +489,13 @@ public int run() throws IOException {
487489
}
488490
// ensuring that the finalize steps detects that no code was seen.
489491
Path srcFolder = Paths.get(EnvironmentVariables.getWipDatabase(), "src");
490-
// check that the srcFolder is empty
491-
if (Files.list(srcFolder).count() == 0) {
492+
try {
492493
// Non-recursive delete because "src/" should be empty.
493494
FileUtil8.delete(srcFolder);
495+
} catch (NoSuchFileException e) {
496+
Exceptions.ignore(e, "the directory did not exist");
497+
} catch (DirectoryNotEmptyException e) {
498+
Exceptions.ignore(e, "just leave the directory if it is not empty");
494499
}
495500
return 0;
496501
}
@@ -1230,11 +1235,12 @@ private void doExtract(FileExtractor extractor, Path file, ExtractorState state)
12301235
if (!extractor.getConfig().isExterns() && (loc == null || loc.getLinesOfCode() != 0)) seenCode = true;
12311236
if (!extractor.getConfig().isExterns()) seenFiles = true;
12321237
for (ParseError err : loc.getParseErrors()) {
1233-
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.";
1238+
String msg = "A parse error occurred: " + StringUtil.escapeMarkdown(err.getMessage())
1239+
+ ". Check the syntax of the file. If the file is invalid, correct the error or exclude the file from analysis.";
12341240
// file, relative to the source root
1235-
String relativeFilePath = file.toString();
1236-
if (relativeFilePath.startsWith(LGTM_SRC.toString())) {
1237-
relativeFilePath = relativeFilePath.substring(LGTM_SRC.toString().length() + 1);
1241+
String relativeFilePath = null;
1242+
if (file.startsWith(LGTM_SRC)) {
1243+
relativeFilePath = file.subpath(LGTM_SRC.getNameCount(), file.getNameCount()).toString();
12381244
}
12391245
DiagnosticLocation diagLoc = DiagnosticLocation.builder()
12401246
.setFile(relativeFilePath)
@@ -1255,7 +1261,7 @@ private void doExtract(FileExtractor extractor, Path file, ExtractorState state)
12551261
try {
12561262
writeDiagnostics("Internal error: " + t, JSDiagnosticKind.INTERNAL_ERROR);
12571263
} catch (IOException ignored) {
1258-
// ignore - we are already crashing
1264+
Exceptions.ignore(ignored, "we are already crashing");
12591265
}
12601266
System.exit(1);
12611267
}

javascript/extractor/src/com/semmle/js/extractor/test/NodeJSDetectorTests.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.semmle.js.extractor.test;
22

3-
import java.io.File;
4-
53
import com.semmle.js.ast.Node;
64
import com.semmle.js.extractor.ExtractionMetrics;
75
import com.semmle.js.extractor.ExtractorConfig;

0 commit comments

Comments
 (0)