comparison mercurial/scmutil.py @ 41419:b5169e79c31c

dispatch: add inline comment about possible IOError subtypes It's hard to tell which "if" would handle which exception.
author Yuya Nishihara <yuya@tcha.org>
date Sat, 26 Jan 2019 17:44:07 +0900
parents a728ef2f9b15
children b6673e9bdcf6
comparison
equal deleted inserted replaced
41418:26761665bdfe 41419:b5169e79c31c
230 if m in "mpatch bdiff".split(): 230 if m in "mpatch bdiff".split():
231 ui.error(_("(did you forget to compile extensions?)\n")) 231 ui.error(_("(did you forget to compile extensions?)\n"))
232 elif m in "zlib".split(): 232 elif m in "zlib".split():
233 ui.error(_("(is your Python install correct?)\n")) 233 ui.error(_("(is your Python install correct?)\n"))
234 except IOError as inst: 234 except IOError as inst:
235 if util.safehasattr(inst, "code"): 235 if util.safehasattr(inst, "code"): # HTTPError
236 ui.error(_("abort: %s\n") % stringutil.forcebytestr(inst)) 236 ui.error(_("abort: %s\n") % stringutil.forcebytestr(inst))
237 elif util.safehasattr(inst, "reason"): 237 elif util.safehasattr(inst, "reason"): # URLError or SSLError
238 try: # usually it is in the form (errno, strerror) 238 try: # usually it is in the form (errno, strerror)
239 reason = inst.reason.args[1] 239 reason = inst.reason.args[1]
240 except (AttributeError, IndexError): 240 except (AttributeError, IndexError):
241 # it might be anything, for example a string 241 # it might be anything, for example a string
242 reason = inst.reason 242 reason = inst.reason
245 reason = encoding.unitolocal(reason) 245 reason = encoding.unitolocal(reason)
246 ui.error(_("abort: error: %s\n") % reason) 246 ui.error(_("abort: error: %s\n") % reason)
247 elif (util.safehasattr(inst, "args") 247 elif (util.safehasattr(inst, "args")
248 and inst.args and inst.args[0] == errno.EPIPE): 248 and inst.args and inst.args[0] == errno.EPIPE):
249 pass 249 pass
250 elif getattr(inst, "strerror", None): 250 elif getattr(inst, "strerror", None): # common IOError
251 if getattr(inst, "filename", None): 251 if getattr(inst, "filename", None):
252 ui.error(_("abort: %s: %s\n") % ( 252 ui.error(_("abort: %s: %s\n") % (
253 encoding.strtolocal(inst.strerror), 253 encoding.strtolocal(inst.strerror),
254 stringutil.forcebytestr(inst.filename))) 254 stringutil.forcebytestr(inst.filename)))
255 else: 255 else:
256 ui.error(_("abort: %s\n") % encoding.strtolocal(inst.strerror)) 256 ui.error(_("abort: %s\n") % encoding.strtolocal(inst.strerror))
257 else: 257 else: # suspicious IOError
258 raise 258 raise
259 except OSError as inst: 259 except OSError as inst:
260 if getattr(inst, "filename", None) is not None: 260 if getattr(inst, "filename", None) is not None:
261 ui.error(_("abort: %s: '%s'\n") % ( 261 ui.error(_("abort: %s: '%s'\n") % (
262 encoding.strtolocal(inst.strerror), 262 encoding.strtolocal(inst.strerror),