From 94d91b682aab27abfd51d50e24688833d9823181 Mon Sep 17 00:00:00 2001 From: KhemrajSingh Rathore Date: Wed, 5 Feb 2025 11:26:19 +0530 Subject: [PATCH] [JsSrc2Cpg] - Handle runtime exception gracefully when filtering astGen result (#5281) --- .../joern/jssrc2cpg/utils/AstGenRunner.scala | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/joern-cli/frontends/jssrc2cpg/src/main/scala/io/joern/jssrc2cpg/utils/AstGenRunner.scala b/joern-cli/frontends/jssrc2cpg/src/main/scala/io/joern/jssrc2cpg/utils/AstGenRunner.scala index 36373372e447..eab0508d0aad 100644 --- a/joern-cli/frontends/jssrc2cpg/src/main/scala/io/joern/jssrc2cpg/utils/AstGenRunner.scala +++ b/joern-cli/frontends/jssrc2cpg/src/main/scala/io/joern/jssrc2cpg/utils/AstGenRunner.scala @@ -270,15 +270,23 @@ class AstGenRunner(config: Config) { private def filterFiles(files: List[String], out: File): List[String] = { files.filter { file => - file.stripSuffix(".json").replace(out.pathAsString, config.inputPath) match { - // We are not interested in JS / TS type definition files at this stage. - // TODO: maybe we can enable that later on and use the type definitions there - // for enhancing the CPG with additional type information for functions - case filePath if TypeDefinitionFileExtensions.exists(filePath.endsWith) => false - case filePath if isIgnoredByUserConfig(filePath) => false - case filePath if isIgnoredByDefault(filePath) => false - case filePath if isTranspiledFile(filePath) => false - case _ => true + Try { + file.stripSuffix(".json").replace(out.pathAsString, config.inputPath) match { + // We are not interested in JS / TS type definition files at this stage. + // TODO: maybe we can enable that later on and use the type definitions there + // for enhancing the CPG with additional type information for functions + case filePath if TypeDefinitionFileExtensions.exists(filePath.endsWith) => false + case filePath if isIgnoredByUserConfig(filePath) => false + case filePath if isIgnoredByDefault(filePath) => false + case filePath if isTranspiledFile(filePath) => false + case _ => true + } + } match { + case Success(result) => result + case Failure(exception) => + // Log the exception for debugging purposes + logger.error("An error occurred while processing the file path during filtering file stage : ", exception) + false } } }