Mercurial > hg
comparison mercurial/dispatch.py @ 7645:020a896a5292
dispatch: sort exception handlers
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Mon, 12 Jan 2009 13:35:35 -0600 |
parents | 182b7114d35a |
children | e62a456b8dc5 |
comparison
equal
deleted
inserted
replaced
7644:182b7114d35a | 7645:020a896a5292 |
---|---|
46 if '--debugger' in args: | 46 if '--debugger' in args: |
47 pdb.post_mortem(sys.exc_info()[2]) | 47 pdb.post_mortem(sys.exc_info()[2]) |
48 ui.print_exc() | 48 ui.print_exc() |
49 raise | 49 raise |
50 | 50 |
51 except error.ParseError, inst: | 51 # Global exception handling, alphabetically |
52 if inst.args[0]: | 52 # Mercurial-specific first, followed by built-in and library exceptions |
53 ui.warn(_("hg %s: %s\n") % (inst.args[0], inst.args[1])) | |
54 commands.help_(ui, inst.args[0]) | |
55 else: | |
56 ui.warn(_("hg: %s\n") % inst.args[1]) | |
57 commands.help_(ui, 'shortlist') | |
58 except error.AmbiguousCommand, inst: | 53 except error.AmbiguousCommand, inst: |
59 ui.warn(_("hg: command '%s' is ambiguous:\n %s\n") % | 54 ui.warn(_("hg: command '%s' is ambiguous:\n %s\n") % |
60 (inst.args[0], " ".join(inst.args[1]))) | 55 (inst.args[0], " ".join(inst.args[1]))) |
61 except error.UnknownCommand, inst: | |
62 ui.warn(_("hg: unknown command '%s'\n") % inst.args[0]) | |
63 commands.help_(ui, 'shortlist') | |
64 except error.RepoError, inst: | |
65 ui.warn(_("abort: %s!\n") % inst) | |
66 except error.LockHeld, inst: | 56 except error.LockHeld, inst: |
67 if inst.errno == errno.ETIMEDOUT: | 57 if inst.errno == errno.ETIMEDOUT: |
68 reason = _('timed out waiting for lock held by %s') % inst.locker | 58 reason = _('timed out waiting for lock held by %s') % inst.locker |
69 else: | 59 else: |
70 reason = _('lock held by %s') % inst.locker | 60 reason = _('lock held by %s') % inst.locker |
71 ui.warn(_("abort: %s: %s\n") % (inst.desc or inst.filename, reason)) | 61 ui.warn(_("abort: %s: %s\n") % (inst.desc or inst.filename, reason)) |
72 except error.LockUnavailable, inst: | 62 except error.LockUnavailable, inst: |
73 ui.warn(_("abort: could not lock %s: %s\n") % | 63 ui.warn(_("abort: could not lock %s: %s\n") % |
74 (inst.desc or inst.filename, inst.strerror)) | 64 (inst.desc or inst.filename, inst.strerror)) |
65 except error.ParseError, inst: | |
66 if inst.args[0]: | |
67 ui.warn(_("hg %s: %s\n") % (inst.args[0], inst.args[1])) | |
68 commands.help_(ui, inst.args[0]) | |
69 else: | |
70 ui.warn(_("hg: %s\n") % inst.args[1]) | |
71 commands.help_(ui, 'shortlist') | |
72 except error.RepoError, inst: | |
73 ui.warn(_("abort: %s!\n") % inst) | |
74 except error.ResponseError, inst: | |
75 ui.warn(_("abort: %s") % inst.args[0]) | |
76 if not isinstance(inst.args[1], basestring): | |
77 ui.warn(" %r\n" % (inst.args[1],)) | |
78 elif not inst.args[1]: | |
79 ui.warn(_(" empty string\n")) | |
80 else: | |
81 ui.warn("\n%r\n" % util.ellipsis(inst.args[1])) | |
75 except error.RevlogError, inst: | 82 except error.RevlogError, inst: |
76 ui.warn(_("abort: %s!\n") % inst) | 83 ui.warn(_("abort: %s!\n") % inst) |
77 except error.SignalInterrupt: | 84 except error.SignalInterrupt: |
78 ui.warn(_("killed!\n")) | 85 ui.warn(_("killed!\n")) |
79 except KeyboardInterrupt: | 86 except error.UnknownCommand, inst: |
80 try: | 87 ui.warn(_("hg: unknown command '%s'\n") % inst.args[0]) |
81 ui.warn(_("interrupted!\n")) | 88 commands.help_(ui, 'shortlist') |
82 except IOError, inst: | 89 except util.Abort, inst: |
83 if inst.errno == errno.EPIPE: | 90 ui.warn(_("abort: %s\n") % inst) |
84 if ui.debugflag: | 91 except ImportError, inst: |
85 ui.warn(_("\nbroken pipe\n")) | 92 m = str(inst).split()[-1] |
86 else: | 93 ui.warn(_("abort: could not import module %s!\n") % m) |
87 raise | 94 if m in "mpatch bdiff".split(): |
88 except socket.error, inst: | 95 ui.warn(_("(did you forget to compile extensions?)\n")) |
89 ui.warn(_("abort: %s\n") % inst.args[-1]) | 96 elif m in "zlib".split(): |
97 ui.warn(_("(is your Python install correct?)\n")) | |
90 except IOError, inst: | 98 except IOError, inst: |
91 if hasattr(inst, "code"): | 99 if hasattr(inst, "code"): |
92 ui.warn(_("abort: %s\n") % inst) | 100 ui.warn(_("abort: %s\n") % inst) |
93 elif hasattr(inst, "reason"): | 101 elif hasattr(inst, "reason"): |
94 try: # usually it is in the form (errno, strerror) | 102 try: # usually it is in the form (errno, strerror) |
109 except OSError, inst: | 117 except OSError, inst: |
110 if getattr(inst, "filename", None): | 118 if getattr(inst, "filename", None): |
111 ui.warn(_("abort: %s: %s\n") % (inst.strerror, inst.filename)) | 119 ui.warn(_("abort: %s: %s\n") % (inst.strerror, inst.filename)) |
112 else: | 120 else: |
113 ui.warn(_("abort: %s\n") % inst.strerror) | 121 ui.warn(_("abort: %s\n") % inst.strerror) |
114 except error.ResponseError, inst: | 122 except KeyboardInterrupt: |
115 ui.warn(_("abort: %s") % inst.args[0]) | 123 try: |
116 if not isinstance(inst.args[1], basestring): | 124 ui.warn(_("interrupted!\n")) |
117 ui.warn(" %r\n" % (inst.args[1],)) | 125 except IOError, inst: |
118 elif not inst.args[1]: | 126 if inst.errno == errno.EPIPE: |
119 ui.warn(_(" empty string\n")) | 127 if ui.debugflag: |
120 else: | 128 ui.warn(_("\nbroken pipe\n")) |
121 ui.warn("\n%r\n" % util.ellipsis(inst.args[1])) | 129 else: |
122 except ImportError, inst: | 130 raise |
123 m = str(inst).split()[-1] | |
124 ui.warn(_("abort: could not import module %s!\n") % m) | |
125 if m in "mpatch bdiff".split(): | |
126 ui.warn(_("(did you forget to compile extensions?)\n")) | |
127 elif m in "zlib".split(): | |
128 ui.warn(_("(is your Python install correct?)\n")) | |
129 | |
130 except util.Abort, inst: | |
131 ui.warn(_("abort: %s\n") % inst) | |
132 except MemoryError: | 131 except MemoryError: |
133 ui.warn(_("abort: out of memory\n")) | 132 ui.warn(_("abort: out of memory\n")) |
134 except SystemExit, inst: | 133 except SystemExit, inst: |
135 # Commands shouldn't sys.exit directly, but give a return code. | 134 # Commands shouldn't sys.exit directly, but give a return code. |
136 # Just in case catch this and and pass exit code to caller. | 135 # Just in case catch this and and pass exit code to caller. |
137 return inst.code | 136 return inst.code |
137 except socket.error, inst: | |
138 ui.warn(_("abort: %s\n") % inst.args[-1]) | |
138 except: | 139 except: |
139 ui.warn(_("** unknown exception encountered, details follow\n")) | 140 ui.warn(_("** unknown exception encountered, details follow\n")) |
140 ui.warn(_("** report bug details to " | 141 ui.warn(_("** report bug details to " |
141 "http://www.selenic.com/mercurial/bts\n")) | 142 "http://www.selenic.com/mercurial/bts\n")) |
142 ui.warn(_("** or mercurial@selenic.com\n")) | 143 ui.warn(_("** or mercurial@selenic.com\n")) |