OLD | NEW |
(Empty) | |
| 1 # |
| 2 # Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The S
Cons Foundation |
| 3 # |
| 4 # Permission is hereby granted, free of charge, to any person obtaining |
| 5 # a copy of this software and associated documentation files (the |
| 6 # "Software"), to deal in the Software without restriction, including |
| 7 # without limitation the rights to use, copy, modify, merge, publish, |
| 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 |
| 10 # the following conditions: |
| 11 # |
| 12 # The above copyright notice and this permission notice shall be included |
| 13 # in all copies or substantial portions of the Software. |
| 14 # |
| 15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY |
| 16 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE |
| 17 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 18 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
| 19 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
| 20 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| 21 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 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 5134 2010/08/16 23:02:40 bdeegan" |
| 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. |
| 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 self.errstr = errstr |
| 97 self.status = status |
| 98 self.exitstatus = exitstatus |
| 99 self.filename = filename |
| 100 self.exc_info = exc_info |
| 101 |
| 102 self.node = node |
| 103 self.executor = executor |
| 104 self.action = action |
| 105 self.command = command |
| 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 |
| 115 |
| 116 class InternalError(Exception): |
| 117 pass |
| 118 |
| 119 class UserError(Exception): |
| 120 pass |
| 121 |
| 122 class StopError(Exception): |
| 123 pass |
| 124 |
| 125 class EnvironmentError(Exception): |
| 126 pass |
| 127 |
| 128 class MSVCError(IOError): |
| 129 pass |
| 130 |
| 131 class ExplicitExit(Exception): |
| 132 def __init__(self, node=None, status=None, *args): |
| 133 self.node = node |
| 134 self.status = status |
| 135 self.exitstatus = status |
| 136 Exception.__init__(self, *args) |
| 137 |
| 138 def convert_to_BuildError(status, exc_info=None): |
| 139 """ |
| 140 Convert any return code a BuildError Exception. |
| 141 |
| 142 `status' can either be a return code or an Exception. |
| 143 The buildError.status we set here will normally be |
| 144 used as the exit status of the "scons" process. |
| 145 """ |
| 146 if not exc_info and isinstance(status, Exception): |
| 147 exc_info = (status.__class__, status, None) |
| 148 |
| 149 if isinstance(status, BuildError): |
| 150 buildError = status |
| 151 buildError.exitstatus = 2 # always exit with 2 on build errors |
| 152 elif isinstance(status, ExplicitExit): |
| 153 status = status.status |
| 154 errstr = 'Explicit exit, status %s' % status |
| 155 buildError = BuildError( |
| 156 errstr=errstr, |
| 157 status=status, # might be 0, OK here |
| 158 exitstatus=status, # might be 0, OK here |
| 159 exc_info=exc_info) |
| 160 elif isinstance(status, (StopError, UserError)): |
| 161 buildError = BuildError( |
| 162 errstr=str(status), |
| 163 status=2, |
| 164 exitstatus=2, |
| 165 exc_info=exc_info) |
| 166 elif isinstance(status, exceptions.EnvironmentError): |
| 167 # If an IOError/OSError happens, raise a BuildError. |
| 168 # Report the name of the file or directory that caused the |
| 169 # error, which might be different from the target being built |
| 170 # (for example, failure to create the directory in which the |
| 171 # target file will appear). |
| 172 try: filename = status.filename |
| 173 except AttributeError: filename = None |
| 174 buildError = BuildError( |
| 175 errstr=status.strerror, |
| 176 status=status.errno, |
| 177 exitstatus=2, |
| 178 filename=filename, |
| 179 exc_info=exc_info) |
| 180 elif isinstance(status, Exception): |
| 181 buildError = BuildError( |
| 182 errstr='%s : %s' % (status.__class__.__name__, status), |
| 183 status=2, |
| 184 exitstatus=2, |
| 185 exc_info=exc_info) |
| 186 elif SCons.Util.is_String(status): |
| 187 buildError = BuildError( |
| 188 errstr=status, |
| 189 status=2, |
| 190 exitstatus=2) |
| 191 else: |
| 192 buildError = BuildError( |
| 193 errstr="Error %s" % status, |
| 194 status=status, |
| 195 exitstatus=2) |
| 196 |
| 197 #import sys |
| 198 #sys.stderr.write("convert_to_BuildError: status %s => (errstr %s, status %s
)"%(status,buildError.errstr, buildError.status)) |
| 199 return buildError |
| 200 |
| 201 # Local Variables: |
| 202 # tab-width:4 |
| 203 # indent-tabs-mode:nil |
| 204 # End: |
| 205 # vim: set expandtab tabstop=4 shiftwidth=4: |
OLD | NEW |