[PATCH] dispatch: allow suppression of the error message for a broken command

Pierre-Yves David pierre-yves.david at ens-lyon.org
Wed Mar 23 17:09:14 EDT 2016



On 03/23/2016 01:56 PM, Martijn Pieters wrote:
> # HG changeset patch
> # User Martijn Pieters <mjpieters at fb.com>
> # Date 1458763469 25200
> #      Wed Mar 23 13:04:29 2016 -0700
> # Node ID a255625e787d00ad2058a7e9cfe6e5581e3eef30
> # Parent  35c2f607a1ebc57bac43e0c658168d2a7b631f87
> dispatch: allow suppression of the error message for a broken command
>
> Add a configuration switch to simply not print the warning and re-raise.
>
> We use an extension to send failures (traceback, warning message) to a central
> location, and end users don't need to see the message. Currently this requires
> us to hack around and either use sys.exit(1) from ui.log('commandfailure') or
> wrapping dispatch to catch the re-raised exception (as well as suppressing
> the ui.warn() call).
>
> diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
> --- a/mercurial/dispatch.py
> +++ b/mercurial/dispatch.py
> @@ -384,6 +384,10 @@
>                       (_("** Extensions loaded: %s\n") %
>                        ", ".join([x[0] for x in extensions.extensions()])))
>           ui.log("commandexception", "%s\n%s\n", warning, traceback.format_exc())
> +        if (ui.configbool('ui', 'suppressfailures', False) and
> +                issubclass(sys.exc_info()[0], Exception)):
> +            # only suppress 'regular' non-system-exit exceptions
> +            return
>           ui.warn(warning)
>           raise
>
> diff --git a/mercurial/help/config.txt b/mercurial/help/config.txt
> --- a/mercurial/help/config.txt
> +++ b/mercurial/help/config.txt
> @@ -1720,6 +1720,12 @@
>   ``statuscopies``
>       Display copies in the status command.
>
> +``suppressfailures``
> +    Do not show a warning message and traceback when Python exception is
> +    raised. Should generally only be used if such failures are redirected
> +    elsewhere by an extension.
> +    (default: False)
> +
>   ``ssh``
>       Command to use for SSH connections. (default: ``ssh``)
>
> diff --git a/tests/test-extension.t b/tests/test-extension.t
> --- a/tests/test-extension.t
> +++ b/tests/test-extension.t
> @@ -883,6 +883,9 @@
>     ** Mercurial Distributed SCM * (glob)
>     ** Extensions loaded: throw
>
> +When ui.suppressfailures is set, no exception warning or traceback is shown:
> +  $ hg --config extensions.throw=throw.py --config ui.suppressfailures=true throw
> +

Either the test failed to be updated or there is something wrong.

There is an error going on here. AS I understand it, the goal here is to 
suppresse the scary traceback. Instead we get nothing. Not even a small 
error message and even more scary, a zero return code.




>   empty declaration of supported version, extension complains:
>     $ echo "testedwith = ''" >> throw.py
>     $ hg --config extensions.throw=throw.py throw 2>&1 | egrep '^\*\*'
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
>

-- 
Pierre-Yves David


More information about the Mercurial-devel mailing list