Skip to content

Commit

Permalink
sflib: remove raise exception in error() function
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoles committed Sep 10, 2020
1 parent b2dda37 commit 2b4108b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 12 deletions.
8 changes: 2 additions & 6 deletions sflib.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ def _dblog(self, level, message, component=None):

return self.dbh.scanLogEvent(self.scanId, level, message, component)

def error(self, message, exception=True):
def error(self, message, exception=False):
"""Print an error message and optionally also raise an exception.
Args:
Expand All @@ -444,11 +444,7 @@ def error(self, message, exception=True):
if self.dbh:
self._dblog("ERROR", message)

if exception:
self.log.exception(message)
raise BaseException(f"Internal Error Encountered: {message}")
else:
self.log.error(message)
self.log.error(message)

def fatal(self, error):
"""Print an error message and stacktrace then exit.
Expand Down
4 changes: 2 additions & 2 deletions sfscan.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def __startScan(self):
try:
module = __import__('modules.' + modName, globals(), locals(), [modName])
except ImportError:
self.__sf.error("Failed to load module: " + modName, False)
self.__sf.error(f"Failed to load module: {modName}")
continue

mod = getattr(module, modName)()
Expand Down Expand Up @@ -350,7 +350,7 @@ def __startScan(self):
exc_type, exc_value, exc_traceback = sys.exc_info()
self.__sf.error(f"Unhandled exception ({e.__class__.__name__}) encountered during scan."
+ "Please report this as a bug: "
+ repr(traceback.format_exception(exc_type, exc_value, exc_traceback)), False)
+ repr(traceback.format_exception(exc_type, exc_value, exc_traceback)))
self.__sf.status(f"Scan [{self.__scanId}] failed: {e}")
self.__setStatus("ERROR-FAILED", None, time.time() * 1000)

Expand Down
5 changes: 1 addition & 4 deletions test/unit/test_spiderfoot.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,16 +188,13 @@ def test_dblog_invalid_dbh_should_raise(self):

def test_error(self):
"""
Test error(self, error, exception=True)
Test error(self, error, exception=False)
"""
sf = SpiderFoot(self.default_options)

sf.error(None, exception=False)
self.assertEqual('TBD', 'TBD')

with self.assertRaises(BaseException):
sf.error(None, exception=True)

def test_fatal_should_exit(self):
"""
Test fatal(self, error)
Expand Down

0 comments on commit 2b4108b

Please sign in to comment.