Skip to content

Commit

Permalink
DCA11Y-1145: Fix unreadable version file exception message to include…
Browse files Browse the repository at this point in the history
… "not"
  • Loading branch information
atl-mk committed Sep 20, 2024
1 parent d9f4116 commit 589f352
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,7 @@ public static String recursivelyFindVersion(File directory) throws Exception {
}

private static String readNvmrcFile(File nvmrcFile, Path nvmrcFilePath, Logger logger) throws Exception {
if (!nvmrcFile.canRead()) {
throw new Exception("Tried to read the node version from the file, but giving up because it's possible to read" + nvmrcFile.getPath());
}
assertNodeVersionFileIsReadable(nvmrcFile);

List<String> lines = Files.readAllLines(nvmrcFilePath);
Optional<String> version = readNvmrcFileLines(lines);
Expand Down Expand Up @@ -134,9 +132,7 @@ static Optional<String> readNvmrcFileLines(List<String> lines) {
}

private static String readToolVersionsFile(File toolVersionsFile, Path toolVersionsFilePath, Logger logger) throws Exception {
if (!toolVersionsFile.canRead()) {
throw new Exception("Tried to read the node version from the file, but giving up because it's possible to read" + toolVersionsFile.getPath());
}
assertNodeVersionFileIsReadable(toolVersionsFile);

List<String> lines = Files.readAllLines(toolVersionsFilePath);
for (String line: lines) {
Expand All @@ -157,4 +153,10 @@ private static String readToolVersionsFile(File toolVersionsFile, Path toolVersi
}
return null;
}

private static void assertNodeVersionFileIsReadable(File file) throws Exception {
if (!file.canRead()) {
throw new Exception("Tried to read the node version from the file, but giving up because it's not possible to read" + file.getPath());
}
}
}

0 comments on commit 589f352

Please sign in to comment.