Fixing uncaught 'InvalidModulePath' exception
When we can't determine a valid module path, we throw an exception, but weren't catching it in node visitor. This resulted in Bandit erroring out if you run it against, for example, setup.py in its own directory. This is certainily an edge-case but catching exceptions is good. Change-Id: I1a91670b398ca70c906bdd5be749105754cd7ff1
This commit is contained in:
parent
7db7f3528b
commit
fc91927698
|
@ -19,6 +19,7 @@ import copy
|
|||
|
||||
import tester as b_tester
|
||||
import utils as b_utils
|
||||
from utils import InvalidModulePath
|
||||
|
||||
|
||||
class StatementBuffer():
|
||||
|
@ -158,7 +159,13 @@ class BanditNodeVisitor(ast.NodeVisitor):
|
|||
self.logger, self.config, self.results, self.testset, self.debug
|
||||
)
|
||||
|
||||
self.namespace = b_utils.get_module_qualname_from_path(fname)
|
||||
# in some cases we can't determine a qualified name
|
||||
try:
|
||||
self.namespace = b_utils.get_module_qualname_from_path(fname)
|
||||
except InvalidModulePath:
|
||||
self.logger.info('Unable to find qualified name for module: {}'
|
||||
.format(self.fname))
|
||||
self.namespace = ""
|
||||
self.logger.debug('Module qualified name: {}'.format(self.namespace))
|
||||
self.stmt_buffer = StatementBuffer()
|
||||
self.statement = {}
|
||||
|
|
Loading…
Reference in New Issue