Patchwork [09,of,10] ui: extend warning about wrong ui

login
register
mail settings
Submitter Simon Heimberg
Date March 22, 2013, 1:20 a.m.
Message ID <32ec0360c7ae215e72e9.1363915259@lapsi.heimberg.home>
Download mbox | patch
Permalink /patch/1163/
State Changes Requested, archived
Headers show

Comments

Simon Heimberg - March 22, 2013, 1:20 a.m.
# HG changeset patch
# User Simon Heimberg <simohe@besonet.ch>
# Date 1349824684 -7200
# Node ID 32ec0360c7ae215e72e9c8a0a810335c0ef66ccd
# Parent  bc3341ad23a61fa0ad272be98cdc00cf11d4b8eb
ui: extend warning about wrong ui

Extend the warning with more info and a stack trace.
This helps the developer to locate the place where a wrong ui object is passed.

Patch

diff -r bc3341ad23a6 -r 32ec0360c7ae mercurial/ui.py
--- a/mercurial/ui.py	Don Okt 04 19:46:43 2012 +0200
+++ b/mercurial/ui.py	Mit Okt 10 01:18:04 2012 +0200
@@ -777,6 +777,8 @@ 
         When a repo or a peer is created, it needs its own configuration. But
         when it gets the ui object of another repo, the configuration from
         there is copied into the new ui object.
+
+        (run the hg command with --debug to get a longer traceback)
         '''
         if self.isglobal:
             return True # passed
@@ -786,5 +788,17 @@ 
             #  TESTTMP is set in mercurial test suite
             #  unittest is a test suite used in many projects
             #  debugflag is set when hg --debug was called
-            self.write_err('PROGRAMMER WARNING: %s\n' % warnmsg)
+            msg = 'PROGRAMMER WARNING: %s\n' \
+                  ' (run pydoc mercurial.ui.checkglobal for more info)\n' \
+                  ' Traceback (most recent call last):\n' % warnmsg
+
+            limit = 8
+            if self.debugflag:
+                limit = 64
+            # traceback, limit calls, start at the caller
+            tb = traceback.format_stack(limit = limit + 1)[:-1]
+            if len(tb) == limit:
+                msg += '  ...\n'
+            msg += ''.join(tb)
+            self.write_err(msg)
         return False