From 148ed9e56f0917ce38d6cde61b252d0a90b3b181 Mon Sep 17 00:00:00 2001 From: KhemrajSingh Rathore Date: Tue, 1 Oct 2024 19:17:47 +0530 Subject: [PATCH] handle invalid file path when reading astGen result (#98) --- .../joern/jssrc2cpg/utils/AstGenRunner.scala | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 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 b818a6e0e774..6560c77ba1dc 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 @@ -259,16 +259,18 @@ 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 + } + }.getOrElse(false) } }