Errors.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/usr/bin/env python
  2. # encoding: utf-8
  3. # Thomas Nagy, 2010-2018 (ita)
  4. """
  5. Exceptions used in the Waf code
  6. """
  7. import traceback, sys
  8. class WafError(Exception):
  9. """Base class for all Waf errors"""
  10. def __init__(self, msg='', ex=None):
  11. """
  12. :param msg: error message
  13. :type msg: string
  14. :param ex: exception causing this error (optional)
  15. :type ex: exception
  16. """
  17. Exception.__init__(self)
  18. self.msg = msg
  19. assert not isinstance(msg, Exception)
  20. self.stack = []
  21. if ex:
  22. if not msg:
  23. self.msg = str(ex)
  24. if isinstance(ex, WafError):
  25. self.stack = ex.stack
  26. else:
  27. self.stack = traceback.extract_tb(sys.exc_info()[2])
  28. self.stack += traceback.extract_stack()[:-1]
  29. self.verbose_msg = ''.join(traceback.format_list(self.stack))
  30. def __str__(self):
  31. return str(self.msg)
  32. class BuildError(WafError):
  33. """Error raised during the build and install phases"""
  34. def __init__(self, error_tasks=[]):
  35. """
  36. :param error_tasks: tasks that could not complete normally
  37. :type error_tasks: list of task objects
  38. """
  39. self.tasks = error_tasks
  40. WafError.__init__(self, self.format_error())
  41. def format_error(self):
  42. """Formats the error messages from the tasks that failed"""
  43. lst = ['Build failed']
  44. for tsk in self.tasks:
  45. txt = tsk.format_error()
  46. if txt:
  47. lst.append(txt)
  48. return '\n'.join(lst)
  49. class ConfigurationError(WafError):
  50. """Configuration exception raised in particular by :py:meth:`waflib.Context.Context.fatal`"""
  51. pass
  52. class TaskRescan(WafError):
  53. """Task-specific exception type signalling required signature recalculations"""
  54. pass
  55. class TaskNotReady(WafError):
  56. """Task-specific exception type signalling that task signatures cannot be computed"""
  57. pass