[PATCH] run: use format() to display error.Error style messages

3 views
Skip to first unread message

Matt Harbison

unread,
Sep 28, 2022, 3:21:31 PM9/28/22
to thg...@googlegroups.com
# HG changeset patch
# User Matt Harbison <matt_h...@yahoo.com>
# Date 1664388602 14400
# Wed Sep 28 14:10:02 2022 -0400
# Branch stable
# Node ID c4fca0a9077f8165565d5f87e7a0e3d9369978f6
# Parent b619f172c9da3520415adf9738d4ada63f7127f5
run: use format() to display error.Error style messages

The previous way lost useful information- specifically ConfigError wouldn't
display the corrupt file and line number. This is also how scmutil.callcatch()
handles it. See https://foss.heptapod.net/mercurial/tortoisehg/thg/-/issues/5830.

The ConfigError case specifically needs the fix in qtlib.earlyBugReport(), but
might as well fix the other places errors are handled too.

diff --git a/tortoisehg/hgqt/qtapp.py b/tortoisehg/hgqt/qtapp.py
--- a/tortoisehg/hgqt/qtapp.py
+++ b/tortoisehg/hgqt/qtapp.py
@@ -112,6 +112,8 @@
'values': [hglib.tounicode(str(e))],
'error': traceback.format_exc(),
'nofork': True}
+ if isinstance(e, error.Error):
+ opts['error'] = hglib.tounicode(e.format())
if isinstance(e, error.ParseError) and e.location:
opts['values'] += [hglib.tounicode(e.location)]
errstring = _recoverableexc[e.__class__]
@@ -124,6 +126,8 @@
"""Show generic errors before the QApplication is started"""
opts = {'cmd': ' '.join(sys.argv[1:]),
'error': traceback.format_exc()}
+ if isinstance(e, error.Error):
+ opts['error'] = hglib.tounicode(e.format())
if not QApplication.instance():
main = QApplication(sys.argv)
dlg = bugreport.BugReport(opts)
diff --git a/tortoisehg/hgqt/run.py b/tortoisehg/hgqt/run.py
--- a/tortoisehg/hgqt/run.py
+++ b/tortoisehg/hgqt/run.py
@@ -363,9 +363,7 @@
except error.RepoError as inst:
ui.warn(_("abort: %s!\n") % inst)
except error.Abort as inst:
- ui.warn(_("abort: %s\n") % inst)
- if inst.hint:
- ui.warn(_("(%s)\n") % inst.hint)
+ ui.warn(inst.format())

return -1

Yuya Nishihara

unread,
Sep 28, 2022, 8:47:56 PM9/28/22
to Matt Harbison, thg...@googlegroups.com
On Wed, 28 Sep 2022 15:21:27 -0400, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_h...@yahoo.com>
> # Date 1664388602 14400
> # Wed Sep 28 14:10:02 2022 -0400
> # Branch stable
> # Node ID c4fca0a9077f8165565d5f87e7a0e3d9369978f6
> # Parent b619f172c9da3520415adf9738d4ada63f7127f5
> run: use format() to display error.Error style messages
>
> The previous way lost useful information- specifically ConfigError wouldn't
> display the corrupt file and line number. This is also how scmutil.callcatch()
> handles it. See https://foss.heptapod.net/mercurial/tortoisehg/thg/-/issues/5830.
>
> The ConfigError case specifically needs the fix in qtlib.earlyBugReport(), but
> might as well fix the other places errors are handled too.
>
> diff --git a/tortoisehg/hgqt/qtapp.py b/tortoisehg/hgqt/qtapp.py
> --- a/tortoisehg/hgqt/qtapp.py
> +++ b/tortoisehg/hgqt/qtapp.py
> @@ -112,6 +112,8 @@
> 'values': [hglib.tounicode(str(e))],
> 'error': traceback.format_exc(),
> 'nofork': True}
> + if isinstance(e, error.Error):
> + opts['error'] = hglib.tounicode(e.format())

opts['error'] contains traceback text. Maybe we need to replace one of the
str(e) with e.format()?

Matt Harbison

unread,
Sep 29, 2022, 11:48:51 AM9/29/22
to TortoiseHg Developers
Oops.

That won't work- earlyBugReport() is the only path that handles ConfigError, and it doesn't str(e) anything.  I'm wondering if this should be fixed on the hg side, maybe by overriding __bytes__() to call format().  But then, ConfigError.format() calls pycompat.bytestr(self.location), which might mangle non-ascii file paths?  The only other thing I can think of is calling traceback.format_exception(), replacing the last entry in the list with hglib.tounicode(e.format()), and creating the opts['error'] string from that.
 
Reply all
Reply to author
Forward
0 new messages