Skip to content

Commit e9129bb

Browse files
committed
#343 Improve error handling for missing srcDir
Check if the source directory exists or if any other IOException occurs while retrieving source documents. Exit if none can be found.
1 parent f70b2b8 commit e9129bb

1 file changed

Lines changed: 18 additions & 8 deletions

File tree

htmlSanityCheck-cli/src/main/groovy/org/aim42/htmlsanitycheck/cli/HscCommand.groovy

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ class HscCommand implements Runnable {
105105
File[] srcDocs
106106

107107
static void main(String[] args) {
108-
109108
HscRunner hscRunner = new HscRunner()
110109
HscCommand hscCommand = new HscCommand(hscRunner)
111110
CommandLine cmd = new CommandLine(hscCommand)
@@ -114,13 +113,24 @@ class HscCommand implements Runnable {
114113
cmd.execute(args)
115114
}
116115

117-
private List<File> findFiles() throws IOException {
118-
Files.walk(Paths.get(srcDir.getPath()))
119-
.filter(Files::isRegularFile)
120-
.filter({ path ->
121-
suffixes.any { suffix -> path.toString().endsWith(".${suffix}") }
122-
})
123-
.collect { Path path -> path.toFile() }
116+
private List<File> findFiles() {
117+
var srcPath = Paths.get(srcDir.getPath())
118+
if (!Files.exists(srcPath)) {
119+
logger.severe("Source directory or file '${srcDir}' does not exist")
120+
System.exit(2)
121+
}
122+
try {
123+
return Files.walk(srcPath)
124+
.filter(Files::isRegularFile)
125+
.filter({ path ->
126+
suffixes.any { suffix -> path.toString().endsWith(".${suffix}") }
127+
})
128+
.collect { Path path -> path.toFile() }
129+
} catch (IOException e) {
130+
logger.severe("Cannot check HTML files in '${srcDir}': '${e}'")
131+
System.exit(2)
132+
}
133+
return null
124134
}
125135

126136
static class HscRunner {

0 commit comments

Comments
 (0)