Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

method return error handling #144

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -344,20 +344,25 @@ abstract class RecoverForXCompilationUnit[CompilationUnitType <: AstNode](
}

override def run(): Unit = {
// Set known aliases that point to imports for local and external methods/modules
importNodes.foreach(visitImport)
// Look at symbols with existing type info
prepopulateSymbolTable()
// Prune import names if the methods exist in the CPG
postVisitImports()
// Populate local symbol table with assignments
assignments.foreach(visitAssignments)
// See if any new information are in the parameters of methods
returns.foreach(visitReturns)
// Persist findings
setTypeInformation()
// Entrypoint for any final changes
postSetTypeInformation()
try {
// Set known aliases that point to imports for local and external methods/modules
importNodes.foreach(visitImport)
// Look at symbols with existing type info
prepopulateSymbolTable()
// Prune import names if the methods exist in the CPG
postVisitImports()
// Populate local symbol table with assignments
assignments.foreach(visitAssignments)
// See if any new information are in the parameters of methods
returns.foreach(visitReturns)
// Persist findings
setTypeInformation()
// Entrypoint for any final changes
postSetTypeInformation()
} catch {
case ex: Exception =>
logger.warn(s"Error in XTypeRecovery ", ex)
}
}

private def debugLocation(n: AstNode): String = {
Expand Down Expand Up @@ -643,7 +648,14 @@ abstract class RecoverForXCompilationUnit[CompilationUnitType <: AstNode](
protected def methodReturnValues(methodFullNames: Seq[String]): Set[String] = {
val rs = cpg.method
.fullNameExact(methodFullNames*)
.methodReturn
.flatMap(method => {
Try(method.methodReturn) match {
case Success(value) => Some(value)
case Failure(exception) =>
logger.warn(s"Error in Type Recovery for method ${method.fullName} from file ${method.filename}")
None
}
})
.flatMap(mr => mr.typeFullName +: (mr.dynamicTypeHintFullName ++ mr.possibleTypes))
.filterNot(_.equals("ANY"))
.toSet
Expand Down
Loading