comparison mercurial/scmutil.py @ 34022:d5b2beca16c0

python3: wrap all uses of <exception>.strerror with strtolocal Our string literals are bytes, and we mostly want to %-format a strerror into a one of those literals, so this fixes a ton of issues.
author Augie Fackler <raf@durin42.com>
date Tue, 22 Aug 2017 20:03:07 -0400
parents 5e83a8fe6bc4
children 9e4f82bc2b0b
comparison
equal deleted inserted replaced
34021:31a2eb0f74e5 34022:d5b2beca16c0
161 ui.warn(_("abort: %s: %s\n") % (inst.desc or inst.filename, reason)) 161 ui.warn(_("abort: %s: %s\n") % (inst.desc or inst.filename, reason))
162 if not inst.locker: 162 if not inst.locker:
163 ui.warn(_("(lock might be very busy)\n")) 163 ui.warn(_("(lock might be very busy)\n"))
164 except error.LockUnavailable as inst: 164 except error.LockUnavailable as inst:
165 ui.warn(_("abort: could not lock %s: %s\n") % 165 ui.warn(_("abort: could not lock %s: %s\n") %
166 (inst.desc or inst.filename, inst.strerror)) 166 (inst.desc or inst.filename,
167 encoding.strtolocal(inst.strerror)))
167 except error.OutOfBandError as inst: 168 except error.OutOfBandError as inst:
168 if inst.args: 169 if inst.args:
169 msg = _("abort: remote error:\n") 170 msg = _("abort: remote error:\n")
170 else: 171 else:
171 msg = _("abort: remote error\n") 172 msg = _("abort: remote error\n")
224 elif (util.safehasattr(inst, "args") 225 elif (util.safehasattr(inst, "args")
225 and inst.args and inst.args[0] == errno.EPIPE): 226 and inst.args and inst.args[0] == errno.EPIPE):
226 pass 227 pass
227 elif getattr(inst, "strerror", None): 228 elif getattr(inst, "strerror", None):
228 if getattr(inst, "filename", None): 229 if getattr(inst, "filename", None):
229 ui.warn(_("abort: %s: %s\n") % (inst.strerror, inst.filename)) 230 ui.warn(_("abort: %s: %s\n") % (
231 encoding.strtolocal(inst.strerror), inst.filename))
230 else: 232 else:
231 ui.warn(_("abort: %s\n") % inst.strerror) 233 ui.warn(_("abort: %s\n") % encoding.strtolocal(inst.strerror))
232 else: 234 else:
233 raise 235 raise
234 except OSError as inst: 236 except OSError as inst:
235 if getattr(inst, "filename", None) is not None: 237 if getattr(inst, "filename", None) is not None:
236 ui.warn(_("abort: %s: '%s'\n") % (inst.strerror, inst.filename)) 238 ui.warn(_("abort: %s: '%s'\n") % (
239 encoding.strtolocal(inst.strerror), inst.filename))
237 else: 240 else:
238 ui.warn(_("abort: %s\n") % inst.strerror) 241 ui.warn(_("abort: %s\n") % encoding.strtolocal(inst.strerror))
239 except MemoryError: 242 except MemoryError:
240 ui.warn(_("abort: out of memory\n")) 243 ui.warn(_("abort: out of memory\n"))
241 except SystemExit as inst: 244 except SystemExit as inst:
242 # Commands shouldn't sys.exit directly, but give a return code. 245 # Commands shouldn't sys.exit directly, but give a return code.
243 # Just in case catch this and and pass exit code to caller. 246 # Just in case catch this and and pass exit code to caller.