OLD | NEW |
1 # | 1 # |
2 # Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 The SCons Foundat
ion | 2 # Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 The SCons Foundat
ion |
3 # | 3 # |
4 # Permission is hereby granted, free of charge, to any person obtaining | 4 # Permission is hereby granted, free of charge, to any person obtaining |
5 # a copy of this software and associated documentation files (the | 5 # a copy of this software and associated documentation files (the |
6 # "Software"), to deal in the Software without restriction, including | 6 # "Software"), to deal in the Software without restriction, including |
7 # without limitation the rights to use, copy, modify, merge, publish, | 7 # without limitation the rights to use, copy, modify, merge, publish, |
8 # distribute, sublicense, and/or sell copies of the Software, and to | 8 # distribute, sublicense, and/or sell copies of the Software, and to |
9 # permit persons to whom the Software is furnished to do so, subject to | 9 # permit persons to whom the Software is furnished to do so, subject to |
10 # the following conditions: | 10 # the following conditions: |
(...skipping 10 matching lines...) Expand all Loading... |
21 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | 21 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
22 # | 22 # |
23 | 23 |
24 """SCons.Errors | 24 """SCons.Errors |
25 | 25 |
26 This file contains the exception classes used to handle internal | 26 This file contains the exception classes used to handle internal |
27 and user errors in SCons. | 27 and user errors in SCons. |
28 | 28 |
29 """ | 29 """ |
30 | 30 |
31 __revision__ = "src/engine/SCons/Errors.py 3603 2008/10/10 05:46:45 scons" | 31 __revision__ = "src/engine/SCons/Errors.py 3842 2008/12/20 22:59:52 scons" |
| 32 |
| 33 import SCons.Util |
| 34 |
| 35 import exceptions |
| 36 |
| 37 class BuildError(Exception): |
| 38 """ Errors occuring while building. |
| 39 |
| 40 BuildError have the following attributes: |
| 41 |
| 42 Information about the cause of the build error: |
| 43 ----------------------------------------------- |
| 44 |
| 45 errstr : a description of the error message |
| 46 |
| 47 status : the return code of the action that caused the build |
| 48 error. Must be set to a non-zero value even if the |
| 49 build error is not due to an action returning a |
| 50 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. |
32 | 71 |
33 | 72 |
| 73 Information about the cause of the location of the error: |
| 74 --------------------------------------------------------- |
34 | 75 |
35 class BuildError(Exception): | 76 node : the error occured while building this target node(s) |
36 def __init__(self, node=None, errstr="Unknown error", status=0, | 77 |
37 filename=None, executor=None, action=None, command=None, | 78 executor : the executor that caused the build to fail (might |
38 *args): | 79 be None if the build failures is not due to the |
39 self.node = node | 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 |
40 self.errstr = errstr | 96 self.errstr = errstr |
41 self.status = status | 97 self.status = status |
| 98 self.exitstatus = exitstatus |
42 self.filename = filename | 99 self.filename = filename |
| 100 self.exc_info = exc_info |
| 101 |
| 102 self.node = node |
43 self.executor = executor | 103 self.executor = executor |
44 self.action = action | 104 self.action = action |
45 self.command = command | 105 self.command = command |
46 apply(Exception.__init__, (self,) + args) | 106 |
| 107 Exception.__init__(self, node, errstr, status, exitstatus, filename, |
| 108 executor, action, command, exc_info) |
| 109 |
| 110 def __str__(self): |
| 111 if self.filename: |
| 112 return self.filename + ': ' + self.errstr |
| 113 else: |
| 114 return self.errstr |
47 | 115 |
48 class InternalError(Exception): | 116 class InternalError(Exception): |
49 pass | 117 pass |
50 | 118 |
51 class UserError(Exception): | 119 class UserError(Exception): |
52 pass | 120 pass |
53 | 121 |
54 class StopError(Exception): | 122 class StopError(Exception): |
55 pass | 123 pass |
56 | 124 |
57 class EnvironmentError(Exception): | 125 class EnvironmentError(Exception): |
58 pass | 126 pass |
59 | 127 |
60 class ExplicitExit(Exception): | 128 class ExplicitExit(Exception): |
61 def __init__(self, node=None, status=None, *args): | 129 def __init__(self, node=None, status=None, *args): |
62 self.node = node | 130 self.node = node |
63 self.status = status | 131 self.status = status |
| 132 self.exitstatus = status |
64 apply(Exception.__init__, (self,) + args) | 133 apply(Exception.__init__, (self,) + args) |
65 | 134 |
66 class TaskmasterException(Exception): | 135 def convert_to_BuildError(status, exc_info=None): |
67 def __init__(self, node=None, exc_info=(None, None, None), *args): | 136 """ |
68 self.node = node | 137 Convert any return code a BuildError Exception. |
69 self.errstr = "Exception" | 138 |
70 self.exc_info = exc_info | 139 `status' can either be a return code or an Exception. |
71 apply(Exception.__init__, (self,) + args) | 140 The buildError.status we set here will normally be |
| 141 used as the exit status of the "scons" process. |
| 142 """ |
| 143 if not exc_info and isinstance(status, Exception): |
| 144 exc_info = (status.__class__, status, None) |
| 145 |
| 146 if isinstance(status, BuildError): |
| 147 buildError = status |
| 148 buildError.exitstatus = 2 # always exit with 2 on build errors |
| 149 elif isinstance(status, ExplicitExit): |
| 150 status = status.status |
| 151 errstr = 'Explicit exit, status %s' % status |
| 152 buildError = BuildError( |
| 153 errstr=errstr, |
| 154 status=status, # might be 0, OK here |
| 155 exitstatus=status, # might be 0, OK here |
| 156 exc_info=exc_info) |
| 157 # TODO(1.5): |
| 158 #elif isinstance(status, (StopError, UserError)): |
| 159 elif isinstance(status, StopError) or isinstance(status, UserError): |
| 160 buildError = BuildError( |
| 161 errstr=str(status), |
| 162 status=2, |
| 163 exitstatus=2, |
| 164 exc_info=exc_info) |
| 165 elif isinstance(status, exceptions.EnvironmentError): |
| 166 # If an IOError/OSError happens, raise a BuildError. |
| 167 # Report the name of the file or directory that caused the |
| 168 # error, which might be different from the target being built |
| 169 # (for example, failure to create the directory in which the |
| 170 # target file will appear). |
| 171 try: filename = status.filename |
| 172 except AttributeError: filename = None |
| 173 buildError = BuildError( |
| 174 errstr=status.strerror, |
| 175 status=status.errno, |
| 176 exitstatus=2, |
| 177 filename=filename, |
| 178 exc_info=exc_info) |
| 179 elif isinstance(status, Exception): |
| 180 buildError = BuildError( |
| 181 errstr='%s : %s' % (status.__class__.__name__, status), |
| 182 status=2, |
| 183 exitstatus=2, |
| 184 exc_info=exc_info) |
| 185 elif SCons.Util.is_String(status): |
| 186 buildError = BuildError( |
| 187 errstr=status, |
| 188 status=2, |
| 189 exitstatus=2) |
| 190 else: |
| 191 buildError = BuildError( |
| 192 errstr="Error %s" % status, |
| 193 status=status, |
| 194 exitstatus=2) |
| 195 |
| 196 #import sys |
| 197 #sys.stderr.write("convert_to_BuildError: status %s => (errstr %s, status %s
)"%(status,buildError.errstr, buildError.status)) |
| 198 return buildError |
OLD | NEW |