| Index: utils/tools.py
|
| diff --git a/utils/tools.py b/utils/tools.py
|
| index eecf709641bc8497a3d8e57480a65b3a8071d029..2885954faca8a2040e4ec9f04fc5779f45ba774d 100644
|
| --- a/utils/tools.py
|
| +++ b/utils/tools.py
|
| @@ -10,6 +10,7 @@ import optparse
|
| import os
|
| import sys
|
| import time
|
| +import traceback
|
|
|
|
|
| class OptionParserWithLogging(optparse.OptionParser):
|
| @@ -112,3 +113,23 @@ def fix_python_path(cmd):
|
| elif out[0].endswith('.py'):
|
| out.insert(0, sys.executable)
|
| return out
|
| +
|
| +
|
| +def report_error(error):
|
| + """Prints a error to stderr, wrapping it into header and footer.
|
| +
|
| + That way errors can be reliably extracted from logs. It's indented to be used
|
| + only for non recoverable unexpected errors. Is should NOT be used for input
|
| + validation, command line argument errors, etc.
|
| +
|
| + Arguments:
|
| + error: error message string (possibly multiple lines) or an instance of
|
| + Exception subclass. In the later case a traceback will also be
|
| + reported. It's assumed that |report_error| is called in an except
|
| + block where |error| was caught.
|
| + """
|
| + print >> sys.stderr, '[------ Swarming Error ------]'
|
| + print >> sys.stderr, str(error)
|
| + if isinstance(error, Exception):
|
| + print >> sys.stderr, traceback.format_exc(),
|
| + print >> sys.stderr, '[----------------------------]'
|
|
|