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 3a41ed6b288cee8d085373ad7fa02894e1903864 2019-01-23 17:30:35 bdeegan"
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_String(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 filename = getattr(status, 'filename', None)
194 strerror = getattr(status, 'strerror', str(status))
195 errno = getattr(status, 'errno', 2)
196
197 buildError = BuildError(
198 errstr=strerror,
199 status=errno,
200 exitstatus=2,
201 filename=filename,
202 exc_info=exc_info)
203 elif isinstance(status, Exception):
204 buildError = BuildError(
205 errstr='%s : %s' % (status.__class__.__name__, status),
206 status=2,
207 exitstatus=2,
208 exc_info=exc_info)
209 elif SCons.Util.is_String(status):
210 buildError = BuildError(
211 errstr=status,
212 status=2,
213 exitstatus=2)
214 else:
215 buildError = BuildError(
216 errstr="Error %s" % status,
217 status=status,
218 exitstatus=2)
219
220
221
222 return buildError
223
224
225
226
227
228
229