Patchwork [1,of,3] dispatch: add inline comment about possible IOError subtypes

login
register
mail settings
Submitter Yuya Nishihara
Date Jan. 26, 2019, 9:24 a.m.
Message ID <f9eab964f2eaa3fe7ad9.1548494669@mimosa>
Download mbox | patch
Permalink /patch/38082/
State Accepted
Headers show

Comments

Yuya Nishihara - Jan. 26, 2019, 9:24 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1548492247 -32400
#      Sat Jan 26 17:44:07 2019 +0900
# Node ID f9eab964f2eaa3fe7ad9f92344b4919ef4514858
# Parent  4a409c19831fb83171e4e65e02ba57da9eb4c3bd
dispatch: add inline comment about possible IOError subtypes

It's hard to tell which "if" would handle which exception.

Patch

diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -232,9 +232,9 @@  def callcatch(ui, func):
         elif m in "zlib".split():
             ui.error(_("(is your Python install correct?)\n"))
     except IOError as inst:
-        if util.safehasattr(inst, "code"):
+        if util.safehasattr(inst, "code"): # HTTPError
             ui.error(_("abort: %s\n") % stringutil.forcebytestr(inst))
-        elif util.safehasattr(inst, "reason"):
+        elif util.safehasattr(inst, "reason"): # URLError or SSLError
             try: # usually it is in the form (errno, strerror)
                 reason = inst.reason.args[1]
             except (AttributeError, IndexError):
@@ -247,14 +247,14 @@  def callcatch(ui, func):
         elif (util.safehasattr(inst, "args")
               and inst.args and inst.args[0] == errno.EPIPE):
             pass
-        elif getattr(inst, "strerror", None):
+        elif getattr(inst, "strerror", None): # common IOError
             if getattr(inst, "filename", None):
                 ui.error(_("abort: %s: %s\n") % (
                     encoding.strtolocal(inst.strerror),
                     stringutil.forcebytestr(inst.filename)))
             else:
                 ui.error(_("abort: %s\n") % encoding.strtolocal(inst.strerror))
-        else:
+        else: # suspicious IOError
             raise
     except OSError as inst:
         if getattr(inst, "filename", None) is not None: