1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 """SCons.Errors
25
26 This file contains the exception classes used to handle internal
27 and user errors in SCons.
28
29 """
30
31 __revision__ = "src/engine/SCons/Errors.py 74b2c53bc42290e911b334a6b44f187da698a668 2017/11/14 13:16:53 bdbaddog"
32
33 import shutil
34 import SCons.Util
35
36
38 """ Errors occurring while building.
39
40 BuildError have the following attributes:
41 =========================================
42
43 Information about the cause of the build error:
44 -----------------------------------------------
45
46 errstr : a description of the error message
47
48 status : the return code of the action that caused the build error.
49 Must be set to a non-zero value even if the build error is not due
50 to an action returning a non-zero returned code.
51
52 exitstatus : SCons exit status due to this build error.
53 Must be nonzero unless due to an explicit Exit()
54 call. Not always the same as status, since
55 actions return a status code that should be
56 respected, but SCons typically exits with 2
57 irrespective of the return value of the failed
58 action.
59
60 filename : The name of the file or directory that caused the
61 build error. Set to None if no files are associated with
62 this error. This might be different from the target
63 being built. For example, failure to create the
64 directory in which the target file will appear. It
65 can be None if the error is not due to a particular
66 filename.
67
68 exc_info : Info about exception that caused the build
69 error. Set to (None, None, None) if this build
70 error is not due to an exception.
71
72
73 Information about the cause of the location of the error:
74 ---------------------------------------------------------
75
76 node : the error occured while building this target node(s)
77
78 executor : the executor that caused the build to fail (might
79 be None if the build failures is not due to the
80 executor failing)
81
82 action : the action that caused the build to fail (might be
83 None if the build failures is not due to the an
84 action failure)
85
86 command : the command line for the action that caused the
87 build to fail (might be None if the build failures
88 is not due to the an action failure)
89 """
90
91 - def __init__(self,
92 node=None, errstr="Unknown error", status=2, exitstatus=2,
93 filename=None, executor=None, action=None, command=None,
94 exc_info=(None, None, None)):
95
96
97
98 self.errstr = SCons.Util.to_str(errstr)
99 self.status = status
100 self.exitstatus = exitstatus
101 self.filename = filename
102 self.exc_info = exc_info
103
104 self.node = node
105 self.executor = executor
106 self.action = action
107 self.command = command
108
109 Exception.__init__(self, node, errstr, status, exitstatus, filename,
110 executor, action, command, exc_info)
111
113 if self.filename:
114 return self.filename + ': ' + self.errstr
115 else:
116 return self.errstr
117
120
123
126
129
132
134 - def __init__(self, node=None, status=None, *args):
135 self.node = node
136 self.status = status
137 self.exitstatus = status
138 Exception.__init__(self, *args)
139
141 """
142 Convert any return code a BuildError Exception.
143
144 :Parameters:
145 - `status`: can either be a return code or an Exception.
146
147 The buildError.status we set here will normally be
148 used as the exit status of the "scons" process.
149 """
150
151 if not exc_info and isinstance(status, Exception):
152 exc_info = (status.__class__, status, None)
153
154
155 if isinstance(status, BuildError):
156 buildError = status
157 buildError.exitstatus = 2
158 elif isinstance(status, ExplicitExit):
159 status = status.status
160 errstr = 'Explicit exit, status %s' % status
161 buildError = BuildError(
162 errstr=errstr,
163 status=status,
164 exitstatus=status,
165 exc_info=exc_info)
166 elif isinstance(status, (StopError, UserError)):
167 buildError = BuildError(
168 errstr=str(status),
169 status=2,
170 exitstatus=2,
171 exc_info=exc_info)
172 elif isinstance(status, shutil.SameFileError):
173
174
175 try:
176 filename = status.filename
177 except AttributeError:
178 filename = None
179
180 buildError = BuildError(
181 errstr=status.args[0],
182 status=status.errno,
183 exitstatus=2,
184 filename=filename,
185 exc_info=exc_info)
186
187 elif isinstance(status, (EnvironmentError, OSError, IOError)):
188
189
190
191
192
193 try:
194 filename = status.filename
195 except AttributeError:
196 filename = None
197
198 buildError = BuildError(
199 errstr=status.strerror,
200 status=status.errno,
201 exitstatus=2,
202 filename=filename,
203 exc_info=exc_info)
204 elif isinstance(status, Exception):
205 buildError = BuildError(
206 errstr='%s : %s' % (status.__class__.__name__, status),
207 status=2,
208 exitstatus=2,
209 exc_info=exc_info)
210 elif SCons.Util.is_String(status):
211 buildError = BuildError(
212 errstr=status,
213 status=2,
214 exitstatus=2)
215 else:
216 buildError = BuildError(
217 errstr="Error %s" % status,
218 status=status,
219 exitstatus=2)
220
221
222
223 return buildError
224
225
226
227
228
229
230