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