##// END OF EJS Templates
py3: convert arbitrary exception object to byte string more reliably...
Yuya Nishihara -
r33645:1d5e497c default
parent child Browse files
Show More
@@ -1045,7 +1045,7 b' class bundlepart(object):'
1045 ui.debug('bundle2-generatorexit\n')
1045 ui.debug('bundle2-generatorexit\n')
1046 raise
1046 raise
1047 except BaseException as exc:
1047 except BaseException as exc:
1048 bexc = pycompat.bytestr(exc)
1048 bexc = util.forcebytestr(exc)
1049 # backup exception data for later
1049 # backup exception data for later
1050 ui.debug('bundle2-input-stream-interrupt: encoding exception %s'
1050 ui.debug('bundle2-input-stream-interrupt: encoding exception %s'
1051 % bexc)
1051 % bexc)
@@ -19,7 +19,6 b' from .i18n import ('
19 from . import (
19 from . import (
20 cmdutil,
20 cmdutil,
21 configitems,
21 configitems,
22 encoding,
23 error,
22 error,
24 pycompat,
23 pycompat,
25 util,
24 util,
@@ -114,16 +113,11 b' def _importext(name, path=None, reportfu'
114 mod = _importh(name)
113 mod = _importh(name)
115 return mod
114 return mod
116
115
117 def _forbytes(inst):
118 """Portably format an import error into a form suitable for
119 %-formatting into bytestrings."""
120 return encoding.strtolocal(str(inst))
121
122 def _reportimporterror(ui, err, failed, next):
116 def _reportimporterror(ui, err, failed, next):
123 # note: this ui.debug happens before --debug is processed,
117 # note: this ui.debug happens before --debug is processed,
124 # Use --config ui.debug=1 to see them.
118 # Use --config ui.debug=1 to see them.
125 ui.debug('could not import %s (%s): trying %s\n'
119 ui.debug('could not import %s (%s): trying %s\n'
126 % (failed, _forbytes(err), next))
120 % (failed, util.forcebytestr(err), next))
127 if ui.debugflag:
121 if ui.debugflag:
128 ui.traceback()
122 ui.traceback()
129
123
@@ -180,7 +174,7 b' def _runuisetup(name, ui):'
180 uisetup(ui)
174 uisetup(ui)
181 except Exception as inst:
175 except Exception as inst:
182 ui.traceback()
176 ui.traceback()
183 msg = _forbytes(inst)
177 msg = util.forcebytestr(inst)
184 ui.warn(_("*** failed to set up extension %s: %s\n") % (name, msg))
178 ui.warn(_("*** failed to set up extension %s: %s\n") % (name, msg))
185 return False
179 return False
186 return True
180 return True
@@ -197,7 +191,7 b' def _runextsetup(name, ui):'
197 extsetup() # old extsetup with no ui argument
191 extsetup() # old extsetup with no ui argument
198 except Exception as inst:
192 except Exception as inst:
199 ui.traceback()
193 ui.traceback()
200 msg = _forbytes(inst)
194 msg = util.forcebytestr(inst)
201 ui.warn(_("*** failed to set up extension %s: %s\n") % (name, msg))
195 ui.warn(_("*** failed to set up extension %s: %s\n") % (name, msg))
202 return False
196 return False
203 return True
197 return True
@@ -215,7 +209,7 b' def loadall(ui, whitelist=None):'
215 try:
209 try:
216 load(ui, name, path)
210 load(ui, name, path)
217 except Exception as inst:
211 except Exception as inst:
218 msg = _forbytes(inst)
212 msg = util.forcebytestr(inst)
219 if path:
213 if path:
220 ui.warn(_("*** failed to import extension %s from %s: %s\n")
214 ui.warn(_("*** failed to import extension %s from %s: %s\n")
221 % (name, path, msg))
215 % (name, path, msg))
@@ -2268,6 +2268,15 b' def escapestr(s):'
2268 def unescapestr(s):
2268 def unescapestr(s):
2269 return codecs.escape_decode(s)[0]
2269 return codecs.escape_decode(s)[0]
2270
2270
2271 def forcebytestr(obj):
2272 """Portably format an arbitrary object (e.g. exception) into a byte
2273 string."""
2274 try:
2275 return pycompat.bytestr(obj)
2276 except UnicodeEncodeError:
2277 # non-ascii string, may be lossy
2278 return pycompat.bytestr(encoding.strtolocal(str(obj)))
2279
2271 def uirepr(s):
2280 def uirepr(s):
2272 # Avoid double backslash in Windows path repr()
2281 # Avoid double backslash in Windows path repr()
2273 return repr(s).replace('\\\\', '\\')
2282 return repr(s).replace('\\\\', '\\')
General Comments 0
You need to be logged in to leave comments. Login now