diff --git a/cuckoo.py b/cuckoo.py index 816126c42a..eb7d10f4fa 100755 --- a/cuckoo.py +++ b/cuckoo.py @@ -8,12 +8,14 @@ import logging import os import sys +import traceback try: from lib.cuckoo.common.constants import CUCKOO_VERSION, CUCKOO_ROOT from lib.cuckoo.common.exceptions import CuckooCriticalError from lib.cuckoo.common.exceptions import CuckooDependencyError from lib.cuckoo.common.logo import logo + from lib.cuckoo.common.utils import exception_message from lib.cuckoo.core.resultserver import ResultServer from lib.cuckoo.core.scheduler import Scheduler from lib.cuckoo.core.startup import check_working_directory, check_configs @@ -116,7 +118,6 @@ def cuckoo_main(max_analysis_count=0): try: cuckoo_init(quiet=args.quiet, debug=args.debug, artwork=args.artwork, test=args.test) - if not args.artwork and not args.test: cuckoo_main(max_analysis_count=args.max_analysis_count) except CuckooCriticalError as e: @@ -125,5 +126,9 @@ def cuckoo_main(max_analysis_count=0): log.critical(message) else: sys.stderr.write("{0}\n".format(message)) - sys.exit(1) + except: + # Deal with an unhandled exception. + message = exception_message() + traceback = traceback.format_exc() + print message, traceback diff --git a/lib/cuckoo/common/utils.py b/lib/cuckoo/common/utils.py index 6cf94cdf02..c6775f9a25 100644 --- a/lib/cuckoo/common/utils.py +++ b/lib/cuckoo/common/utils.py @@ -5,6 +5,7 @@ import hashlib import os +import sys import shutil import ntpath import string @@ -18,6 +19,7 @@ from lib.cuckoo.common.exceptions import CuckooOperationalError from lib.cuckoo.common.config import Config +from lib.cuckoo.common.constants import CUCKOO_VERSION try: import chardet @@ -292,3 +294,24 @@ def md5_file(filepath): def sha1_file(filepath): return hash_file(hashlib.sha1, filepath) + +def exception_message(): + """Creates a message describing an unhandled exception.""" + msg = "Oops! Cuckoo falls in an unhandled exception!\nSometimes a bug " \ + "could be already fixed in the development release, it is " \ + "recommended to retry with the development release available at " \ + "https://github.com/cuckoosandbox/cuckoo\n" \ + "If the error persists please open a new issue at " \ + "https://github.com/cuckoosandbox/cuckoo/issues\n\n" + msg += "=== Exception details ===\n" + msg += "Cuckoo version: %s\n" % CUCKOO_VERSION + msg += "OS version: %s\n" % os.name + msg += "Python version: %s\n" % sys.version.split()[0] + try: + import pip + except ImportError: + pass + else: + msg += "Modules: %s\n" % " ".join(sorted(["%s:%s" % (i.key, i.version) \ + for i in pip.get_installed_distributions()])) + return msg