170 ui.traceback() |
170 ui.traceback() |
171 raise |
171 raise |
172 |
172 |
173 # Global exception handling, alphabetically |
173 # Global exception handling, alphabetically |
174 # Mercurial-specific first, followed by built-in and library exceptions |
174 # Mercurial-specific first, followed by built-in and library exceptions |
175 except error.AmbiguousCommand, inst: |
175 except error.AmbiguousCommand as inst: |
176 ui.warn(_("hg: command '%s' is ambiguous:\n %s\n") % |
176 ui.warn(_("hg: command '%s' is ambiguous:\n %s\n") % |
177 (inst.args[0], " ".join(inst.args[1]))) |
177 (inst.args[0], " ".join(inst.args[1]))) |
178 except error.ParseError, inst: |
178 except error.ParseError as inst: |
179 _formatparse(ui.warn, inst) |
179 _formatparse(ui.warn, inst) |
180 return -1 |
180 return -1 |
181 except error.LockHeld, inst: |
181 except error.LockHeld as inst: |
182 if inst.errno == errno.ETIMEDOUT: |
182 if inst.errno == errno.ETIMEDOUT: |
183 reason = _('timed out waiting for lock held by %s') % inst.locker |
183 reason = _('timed out waiting for lock held by %s') % inst.locker |
184 else: |
184 else: |
185 reason = _('lock held by %s') % inst.locker |
185 reason = _('lock held by %s') % inst.locker |
186 ui.warn(_("abort: %s: %s\n") % (inst.desc or inst.filename, reason)) |
186 ui.warn(_("abort: %s: %s\n") % (inst.desc or inst.filename, reason)) |
187 except error.LockUnavailable, inst: |
187 except error.LockUnavailable as inst: |
188 ui.warn(_("abort: could not lock %s: %s\n") % |
188 ui.warn(_("abort: could not lock %s: %s\n") % |
189 (inst.desc or inst.filename, inst.strerror)) |
189 (inst.desc or inst.filename, inst.strerror)) |
190 except error.CommandError, inst: |
190 except error.CommandError as inst: |
191 if inst.args[0]: |
191 if inst.args[0]: |
192 ui.warn(_("hg %s: %s\n") % (inst.args[0], inst.args[1])) |
192 ui.warn(_("hg %s: %s\n") % (inst.args[0], inst.args[1])) |
193 commands.help_(ui, inst.args[0], full=False, command=True) |
193 commands.help_(ui, inst.args[0], full=False, command=True) |
194 else: |
194 else: |
195 ui.warn(_("hg: %s\n") % inst.args[1]) |
195 ui.warn(_("hg: %s\n") % inst.args[1]) |
196 commands.help_(ui, 'shortlist') |
196 commands.help_(ui, 'shortlist') |
197 except error.OutOfBandError, inst: |
197 except error.OutOfBandError as inst: |
198 if inst.args: |
198 if inst.args: |
199 msg = _("abort: remote error:\n") |
199 msg = _("abort: remote error:\n") |
200 else: |
200 else: |
201 msg = _("abort: remote error\n") |
201 msg = _("abort: remote error\n") |
202 ui.warn(msg) |
202 ui.warn(msg) |
203 if inst.args: |
203 if inst.args: |
204 ui.warn(''.join(inst.args)) |
204 ui.warn(''.join(inst.args)) |
205 if inst.hint: |
205 if inst.hint: |
206 ui.warn('(%s)\n' % inst.hint) |
206 ui.warn('(%s)\n' % inst.hint) |
207 except error.RepoError, inst: |
207 except error.RepoError as inst: |
208 ui.warn(_("abort: %s!\n") % inst) |
208 ui.warn(_("abort: %s!\n") % inst) |
209 if inst.hint: |
209 if inst.hint: |
210 ui.warn(_("(%s)\n") % inst.hint) |
210 ui.warn(_("(%s)\n") % inst.hint) |
211 except error.ResponseError, inst: |
211 except error.ResponseError as inst: |
212 ui.warn(_("abort: %s") % inst.args[0]) |
212 ui.warn(_("abort: %s") % inst.args[0]) |
213 if not isinstance(inst.args[1], basestring): |
213 if not isinstance(inst.args[1], basestring): |
214 ui.warn(" %r\n" % (inst.args[1],)) |
214 ui.warn(" %r\n" % (inst.args[1],)) |
215 elif not inst.args[1]: |
215 elif not inst.args[1]: |
216 ui.warn(_(" empty string\n")) |
216 ui.warn(_(" empty string\n")) |
217 else: |
217 else: |
218 ui.warn("\n%r\n" % util.ellipsis(inst.args[1])) |
218 ui.warn("\n%r\n" % util.ellipsis(inst.args[1])) |
219 except error.CensoredNodeError, inst: |
219 except error.CensoredNodeError as inst: |
220 ui.warn(_("abort: file censored %s!\n") % inst) |
220 ui.warn(_("abort: file censored %s!\n") % inst) |
221 except error.RevlogError, inst: |
221 except error.RevlogError as inst: |
222 ui.warn(_("abort: %s!\n") % inst) |
222 ui.warn(_("abort: %s!\n") % inst) |
223 except error.SignalInterrupt: |
223 except error.SignalInterrupt: |
224 ui.warn(_("killed!\n")) |
224 ui.warn(_("killed!\n")) |
225 except error.UnknownCommand, inst: |
225 except error.UnknownCommand as inst: |
226 ui.warn(_("hg: unknown command '%s'\n") % inst.args[0]) |
226 ui.warn(_("hg: unknown command '%s'\n") % inst.args[0]) |
227 try: |
227 try: |
228 # check if the command is in a disabled extension |
228 # check if the command is in a disabled extension |
229 # (but don't check for extensions themselves) |
229 # (but don't check for extensions themselves) |
230 commands.help_(ui, inst.args[0], unknowncmd=True) |
230 commands.help_(ui, inst.args[0], unknowncmd=True) |
236 ui.warn(_('(did you mean one of %s?)\n') % |
236 ui.warn(_('(did you mean one of %s?)\n') % |
237 ', '.join(sorted(sim))) |
237 ', '.join(sorted(sim))) |
238 suggested = True |
238 suggested = True |
239 if not suggested: |
239 if not suggested: |
240 commands.help_(ui, 'shortlist') |
240 commands.help_(ui, 'shortlist') |
241 except error.InterventionRequired, inst: |
241 except error.InterventionRequired as inst: |
242 ui.warn("%s\n" % inst) |
242 ui.warn("%s\n" % inst) |
243 return 1 |
243 return 1 |
244 except util.Abort, inst: |
244 except util.Abort as inst: |
245 ui.warn(_("abort: %s\n") % inst) |
245 ui.warn(_("abort: %s\n") % inst) |
246 if inst.hint: |
246 if inst.hint: |
247 ui.warn(_("(%s)\n") % inst.hint) |
247 ui.warn(_("(%s)\n") % inst.hint) |
248 except ImportError, inst: |
248 except ImportError as inst: |
249 ui.warn(_("abort: %s!\n") % inst) |
249 ui.warn(_("abort: %s!\n") % inst) |
250 m = str(inst).split()[-1] |
250 m = str(inst).split()[-1] |
251 if m in "mpatch bdiff".split(): |
251 if m in "mpatch bdiff".split(): |
252 ui.warn(_("(did you forget to compile extensions?)\n")) |
252 ui.warn(_("(did you forget to compile extensions?)\n")) |
253 elif m in "zlib".split(): |
253 elif m in "zlib".split(): |
254 ui.warn(_("(is your Python install correct?)\n")) |
254 ui.warn(_("(is your Python install correct?)\n")) |
255 except IOError, inst: |
255 except IOError as inst: |
256 if util.safehasattr(inst, "code"): |
256 if util.safehasattr(inst, "code"): |
257 ui.warn(_("abort: %s\n") % inst) |
257 ui.warn(_("abort: %s\n") % inst) |
258 elif util.safehasattr(inst, "reason"): |
258 elif util.safehasattr(inst, "reason"): |
259 try: # usually it is in the form (errno, strerror) |
259 try: # usually it is in the form (errno, strerror) |
260 reason = inst.reason.args[1] |
260 reason = inst.reason.args[1] |
274 ui.warn(_("abort: %s: %s\n") % (inst.strerror, inst.filename)) |
274 ui.warn(_("abort: %s: %s\n") % (inst.strerror, inst.filename)) |
275 else: |
275 else: |
276 ui.warn(_("abort: %s\n") % inst.strerror) |
276 ui.warn(_("abort: %s\n") % inst.strerror) |
277 else: |
277 else: |
278 raise |
278 raise |
279 except OSError, inst: |
279 except OSError as inst: |
280 if getattr(inst, "filename", None) is not None: |
280 if getattr(inst, "filename", None) is not None: |
281 ui.warn(_("abort: %s: '%s'\n") % (inst.strerror, inst.filename)) |
281 ui.warn(_("abort: %s: '%s'\n") % (inst.strerror, inst.filename)) |
282 else: |
282 else: |
283 ui.warn(_("abort: %s\n") % inst.strerror) |
283 ui.warn(_("abort: %s\n") % inst.strerror) |
284 except KeyboardInterrupt: |
284 except KeyboardInterrupt: |
285 try: |
285 try: |
286 ui.warn(_("interrupted!\n")) |
286 ui.warn(_("interrupted!\n")) |
287 except IOError, inst: |
287 except IOError as inst: |
288 if inst.errno == errno.EPIPE: |
288 if inst.errno == errno.EPIPE: |
289 if ui.debugflag: |
289 if ui.debugflag: |
290 ui.warn(_("\nbroken pipe\n")) |
290 ui.warn(_("\nbroken pipe\n")) |
291 else: |
291 else: |
292 raise |
292 raise |
293 except MemoryError: |
293 except MemoryError: |
294 ui.warn(_("abort: out of memory\n")) |
294 ui.warn(_("abort: out of memory\n")) |
295 except SystemExit, inst: |
295 except SystemExit as inst: |
296 # Commands shouldn't sys.exit directly, but give a return code. |
296 # Commands shouldn't sys.exit directly, but give a return code. |
297 # Just in case catch this and and pass exit code to caller. |
297 # Just in case catch this and and pass exit code to caller. |
298 return inst.code |
298 return inst.code |
299 except socket.error, inst: |
299 except socket.error as inst: |
300 ui.warn(_("abort: %s\n") % inst.args[-1]) |
300 ui.warn(_("abort: %s\n") % inst.args[-1]) |
301 except: # re-raises |
301 except: # re-raises |
302 myver = util.version() |
302 myver = util.version() |
303 # For compatibility checking, we discard the portion of the hg |
303 # For compatibility checking, we discard the portion of the hg |
304 # version after the + on the assumption that if a "normal |
304 # version after the + on the assumption that if a "normal |