comparison mercurial/dispatch.py @ 24039:2ee35b6ee4fb

dispatch: consolidate formatting of ParseErrors
author Augie Fackler <augie@google.com>
date Mon, 26 Jan 2015 14:50:36 -0500
parents b2d8f3685b06
children bb11081562d7
comparison
equal deleted inserted replaced
24038:10d02cd18604 24039:2ee35b6ee4fb
24 self.ferr = ferr 24 self.ferr = ferr
25 25
26 def run(): 26 def run():
27 "run the command in sys.argv" 27 "run the command in sys.argv"
28 sys.exit((dispatch(request(sys.argv[1:])) or 0) & 255) 28 sys.exit((dispatch(request(sys.argv[1:])) or 0) & 255)
29
30 def _formatparse(write, inst):
31 if len(inst.args) > 1:
32 write(_("hg: parse error at %s: %s\n") %
33 (inst.args[1], inst.args[0]))
34 if (inst.args[0][0] == ' '):
35 write(_("unexpected leading whitespace\n"))
36 else:
37 write(_("hg: parse error: %s\n") % inst.args[0])
29 38
30 def dispatch(req): 39 def dispatch(req):
31 "run the command specified in req.args" 40 "run the command specified in req.args"
32 if req.ferr: 41 if req.ferr:
33 ferr = req.ferr 42 ferr = req.ferr
53 ferr.write(_("abort: %s\n") % inst) 62 ferr.write(_("abort: %s\n") % inst)
54 if inst.hint: 63 if inst.hint:
55 ferr.write(_("(%s)\n") % inst.hint) 64 ferr.write(_("(%s)\n") % inst.hint)
56 return -1 65 return -1
57 except error.ParseError, inst: 66 except error.ParseError, inst:
58 if len(inst.args) > 1: 67 _formatparse(ferr.write, inst)
59 ferr.write(_("hg: parse error at %s: %s\n") %
60 (inst.args[1], inst.args[0]))
61 if (inst.args[0][0] == ' '):
62 ferr.write(_("unexpected leading whitespace\n"))
63 else:
64 ferr.write(_("hg: parse error: %s\n") % inst.args[0])
65 return -1 68 return -1
66 69
67 msg = ' '.join(' ' in a and repr(a) or a for a in req.args) 70 msg = ' '.join(' ' in a and repr(a) or a for a in req.args)
68 starttime = time.time() 71 starttime = time.time()
69 ret = None 72 ret = None
152 # Mercurial-specific first, followed by built-in and library exceptions 155 # Mercurial-specific first, followed by built-in and library exceptions
153 except error.AmbiguousCommand, inst: 156 except error.AmbiguousCommand, inst:
154 ui.warn(_("hg: command '%s' is ambiguous:\n %s\n") % 157 ui.warn(_("hg: command '%s' is ambiguous:\n %s\n") %
155 (inst.args[0], " ".join(inst.args[1]))) 158 (inst.args[0], " ".join(inst.args[1])))
156 except error.ParseError, inst: 159 except error.ParseError, inst:
157 if len(inst.args) > 1: 160 _formatparse(ui.warn, inst)
158 ui.warn(_("hg: parse error at %s: %s\n") %
159 (inst.args[1], inst.args[0]))
160 if (inst.args[0][0] == ' '):
161 ui.warn(_("unexpected leading whitespace\n"))
162 else:
163 ui.warn(_("hg: parse error: %s\n") % inst.args[0])
164 return -1 161 return -1
165 except error.LockHeld, inst: 162 except error.LockHeld, inst:
166 if inst.errno == errno.ETIMEDOUT: 163 if inst.errno == errno.ETIMEDOUT:
167 reason = _('timed out waiting for lock held by %s') % inst.locker 164 reason = _('timed out waiting for lock held by %s') % inst.locker
168 else: 165 else: