Mercurial > hg
comparison mercurial/extensions.py @ 31303:90f439823b99
extensions: tapdance to get reasonable import error formatting
I'm not thrilled with this, but it seems to work.
author | Augie Fackler <raf@durin42.com> |
---|---|
date | Fri, 03 Mar 2017 14:08:02 -0500 |
parents | 063d7957fa12 |
children | 067add650129 |
comparison
equal
deleted
inserted
replaced
31302:681046de87f1 | 31303:90f439823b99 |
---|---|
16 gettext, | 16 gettext, |
17 ) | 17 ) |
18 | 18 |
19 from . import ( | 19 from . import ( |
20 cmdutil, | 20 cmdutil, |
21 encoding, | |
21 error, | 22 error, |
22 pycompat, | 23 pycompat, |
23 util, | 24 util, |
24 ) | 25 ) |
25 | 26 |
102 if reportfunc: | 103 if reportfunc: |
103 reportfunc(err, "hgext3rd.%s" % name, name) | 104 reportfunc(err, "hgext3rd.%s" % name, name) |
104 mod = _importh(name) | 105 mod = _importh(name) |
105 return mod | 106 return mod |
106 | 107 |
108 def _forbytes(inst): | |
109 """Portably format an import error into a form suitable for | |
110 %-formatting into bytestrings.""" | |
111 if pycompat.ispy3: | |
112 return encoding.tolocal(str(inst).encode('utf-8')) | |
113 return inst | |
114 | |
107 def _reportimporterror(ui, err, failed, next): | 115 def _reportimporterror(ui, err, failed, next): |
108 # note: this ui.debug happens before --debug is processed, | 116 # note: this ui.debug happens before --debug is processed, |
109 # Use --config ui.debug=1 to see them. | 117 # Use --config ui.debug=1 to see them. |
110 ui.debug('could not import %s (%s): trying %s\n' | 118 ui.debug('could not import %s (%s): trying %s\n' |
111 % (failed, err, next)) | 119 % (failed, _forbytes(err), next)) |
112 if ui.debugflag: | 120 if ui.debugflag: |
113 ui.traceback() | 121 ui.traceback() |
114 | 122 |
115 def load(ui, name, path): | 123 def load(ui, name, path): |
116 if name.startswith('hgext.') or name.startswith('hgext/'): | 124 if name.startswith('hgext.') or name.startswith('hgext/'): |
166 try: | 174 try: |
167 load(ui, name, path) | 175 load(ui, name, path) |
168 except KeyboardInterrupt: | 176 except KeyboardInterrupt: |
169 raise | 177 raise |
170 except Exception as inst: | 178 except Exception as inst: |
179 inst = _forbytes(inst) | |
171 if path: | 180 if path: |
172 ui.warn(_("*** failed to import extension %s from %s: %s\n") | 181 ui.warn(_("*** failed to import extension %s from %s: %s\n") |
173 % (name, path, inst)) | 182 % (name, path, inst)) |
174 else: | 183 else: |
175 ui.warn(_("*** failed to import extension %s: %s\n") | 184 ui.warn(_("*** failed to import extension %s: %s\n") |