Skip to content
This repository was archived by the owner on Oct 15, 2020. It is now read-only.

Commit eaf4c1a

Browse files
authored
Return a non zero exit code in case of invalid options. (#237)
I found this debugging problems in code which make the very valid assumption that this program returns non zero in case of errors.
1 parent 6e48d9e commit eaf4c1a

File tree

1 file changed

+27
-23
lines changed

1 file changed

+27
-23
lines changed

src/main/scala/io/shiftleft/fuzzyc2cpg/FuzzyC2Cpg.scala

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -117,30 +117,34 @@ object FuzzyC2Cpg {
117117
private val logger = LoggerFactory.getLogger(classOf[FuzzyC2Cpg])
118118

119119
def main(args: Array[String]): Unit = {
120-
parseConfig(args).foreach { config =>
121-
try {
122-
val fuzzyc = new FuzzyC2Cpg()
123-
124-
if (config.usePreprocessor) {
125-
fuzzyc.runWithPreprocessorAndOutput(
126-
config.inputPaths,
127-
config.sourceFileExtensions,
128-
config.includeFiles,
129-
config.includePaths,
130-
config.defines,
131-
config.undefines,
132-
config.preprocessorExecutable,
133-
Some(config.outputPath)
134-
)
135-
} else {
136-
val cpg = fuzzyc.runAndOutput(config.inputPaths, config.sourceFileExtensions, Some(config.outputPath))
137-
cpg.close()
120+
parseConfig(args) match {
121+
case Some(config) =>
122+
try {
123+
val fuzzyc = new FuzzyC2Cpg()
124+
125+
if (config.usePreprocessor) {
126+
fuzzyc.runWithPreprocessorAndOutput(
127+
config.inputPaths,
128+
config.sourceFileExtensions,
129+
config.includeFiles,
130+
config.includePaths,
131+
config.defines,
132+
config.undefines,
133+
config.preprocessorExecutable,
134+
Some(config.outputPath)
135+
)
136+
} else {
137+
val cpg = fuzzyc.runAndOutput(config.inputPaths, config.sourceFileExtensions, Some(config.outputPath))
138+
cpg.close()
139+
}
140+
141+
} catch {
142+
case NonFatal(ex) =>
143+
logger.error("Failed to generate CPG.", ex)
144+
System.exit(1)
138145
}
139-
140-
} catch {
141-
case NonFatal(ex) =>
142-
logger.error("Failed to generate CPG.", ex)
143-
}
146+
case _ =>
147+
System.exit(1)
144148
}
145149
}
146150

0 commit comments

Comments
 (0)