Samsung / CredSweeper

CredSweeper is a tool to detect credentials in any directories or files. CredSweeper could help users to detect unwanted exposure of credentials (such as token, passwords, api keys etc.) in advance. By scanning lines, filtering, and using AI model as option, CredSweeper reports lines with possible credentials, where the line is, and expected type o

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Too long message on KeyboardInterrupt

meanrin opened this issue · comments

In case if user stops credsweeper during the long scan it will produce a very long error message that looks like

...
Process SpawnPoolWorker-4:
Traceback (most recent call last):
  File "/usr/lib/python3.8/multiprocessing/process.py", line 313, in _bootstrap
    self.run()
Traceback (most recent call last):
  File "/usr/lib/python3.8/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/lib/python3.8/multiprocessing/pool.py", line 125, in worker
    result = (True, func(*args, **kwds))
  File "/usr/lib/python3.8/multiprocessing/pool.py", line 48, in mapstar
    return list(map(*args))
  File "/home/user/share/code/credsweeper_replicas/open/CredSweeper/credsweeper/app.py", line 129, in file_scan
    return self.scanner.scan(scanContext)
  File "/home/user/share/code/credsweeper_replicas/open/CredSweeper/credsweeper/scanner/scanner.py", line 47, in scan
    new_credential = self.get_scanner(rule).run(self.config,
  File "/home/user/share/code/credsweeper_replicas/open/CredSweeper/credsweeper/scanner/scan_type/single_pattern.py", line 32, in run
    line_data = cls.get_line_data(config, line, line_num, file_path, rule.patterns[0], rule.filters)
KeyboardInterrupt
  File "/usr/lib/python3.8/multiprocessing/process.py", line 313, in _bootstrap
    self.run()
  File "/usr/lib/python3.8/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/lib/python3.8/multiprocessing/pool.py", line 125, in worker
    result = (True, func(*args, **kwds))
  File "/usr/lib/python3.8/multiprocessing/pool.py", line 48, in mapstar
    return list(map(*args))
  File "/home/user/share/code/credsweeper_replicas/open/CredSweeper/credsweeper/app.py", line 129, in file_scan
    return self.scanner.scan(scanContext)
  File "/home/user/share/code/credsweeper_replicas/open/CredSweeper/credsweeper/scanner/scanner.py", line 47, in scan
    new_credential = self.get_scanner(rule).run(self.config,
  File "/home/user/share/code/credsweeper_replicas/open/CredSweeper/credsweeper/scanner/scan_type/single_pattern.py", line 32, in run
    line_data = cls.get_line_data(config, line, line_num, file_path, rule.patterns[0], rule.filters)
  File "/home/user/share/code/credsweeper_replicas/open/CredSweeper/credsweeper/scanner/scan_type/scan_type.py", line 76, in get_line_data
    if not cls.is_valid_line(line, pattern):
  File "/home/user/share/code/credsweeper_replicas/open/CredSweeper/credsweeper/scanner/scan_type/scan_type.py", line 111, in is_valid_line
    if cls.is_valid_line_length(line) and cls.is_pattern_detected_line(line, pattern):
  File "/home/user/share/code/credsweeper_replicas/open/CredSweeper/credsweeper/scanner/scan_type/scan_type.py", line 96, in is_pattern_detected_line
    if pattern.search(line):
Process SpawnPoolWorker-14:
...

The more processes was used for scan - the longer output will be

While this is typical behavior for all python apps it still creates a bit of discomfort if you tries to debug an app, stops it and now you need to scroll terminal up for 300 lines
And this error message is useless, as it report KeyboardInterrupt while user obviously know that they keyboard-interrupted the app a second ago

This output can be suppressed by adding except KeyboardInterrupt in app.file_scan and __main__.main
Or by specificity signal.signal callback similar to: https://stackoverflow.com/a/57950670

If there is no assignee on this issue, i'll take this issue. 😄