Package SCons :: Module Errors
[hide private]
[frames] | no frames]

Source Code for Module SCons.Errors

  1  # 
  2  # Copyright (c) 2001 - 2019 The SCons 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 3a41ed6b288cee8d085373ad7fa02894e1903864 2019-01-23 17:30:35 bdeegan" 
 32   
 33  import shutil 
 34  import SCons.Util 
 35   
 36   
37 -class BuildError(Exception):
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 # py3: errstr should be string and not bytes. 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
112 - def __str__(self):
113 if self.filename: 114 return self.filename + ': ' + self.errstr 115 else: 116 return self.errstr
117
118 -class InternalError(Exception):
119 pass
120
121 -class UserError(Exception):
122 pass
123
124 -class StopError(Exception):
125 pass
126
127 -class EnvironmentError(Exception):
128 pass
129
130 -class MSVCError(IOError):
131 pass
132
133 -class ExplicitExit(Exception):
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
140 -def convert_to_BuildError(status, exc_info=None):
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 # always exit with 2 on build errors 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, # might be 0, OK here 164 exitstatus=status, # might be 0, OK here 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 # PY3 has a exception for when copying file to itself 174 # It's object provides info differently than below 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 # If an IOError/OSError happens, raise a BuildError. 189 # Report the name of the file or directory that caused the 190 # error, which might be different from the target being built 191 # (for example, failure to create the directory in which the 192 # target file will appear). 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 #import sys 221 #sys.stderr.write("convert_to_BuildError: status %s => (errstr %s, status %s)\n"%(status,buildError.errstr, buildError.status)) 222 return buildError
223 224 # Local Variables: 225 # tab-width:4 226 # indent-tabs-mode:nil 227 # End: 228 # vim: set expandtab tabstop=4 shiftwidth=4: 229