Skip to content

Commit

Permalink
Added unhandled exception message
Browse files Browse the repository at this point in the history
  • Loading branch information
jekil committed Feb 10, 2016
1 parent 1b4b006 commit 88b6936
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
9 changes: 7 additions & 2 deletions cuckoo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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
23 changes: 23 additions & 0 deletions lib/cuckoo/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import hashlib
import os
import sys
import shutil
import ntpath
import string
Expand All @@ -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
Expand Down Expand Up @@ -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

0 comments on commit 88b6936

Please sign in to comment.