# HG changeset patch # User Pierre-Yves David # Date 2022-11-12 01:30:41 # Node ID aab3d4c057209bd241fbbe151d0eb664ebd1e715 # Parent d12446766a359e79ce1e7a8e27d909b586f2d59d profile: prevent a crash when line number is unknown For some unknown reason, `self.lineno` can be None. The previous code crashed in such case, we now ignore the case, as we do for other error in this function. We also fallback to using `-1` in the output when this lack of line number makes it to the display code. The reason of unknown line-numbers is… unknown. diff --git a/mercurial/statprof.py b/mercurial/statprof.py --- a/mercurial/statprof.py +++ b/mercurial/statprof.py @@ -236,8 +236,8 @@ class CodeSite: def getsource(self, length): if self.source is None: - lineno = self.lineno - 1 try: + lineno = self.lineno - 1 # lineno can be None with open(self.path, b'rb') as fp: for i, line in enumerate(fp): if i == lineno: @@ -773,7 +773,7 @@ def display_hotpath(data, fp, limit=0.05 codestring = codepattern % ( prefix, b'line'.rjust(spacing_len), - site.lineno, + site.lineno if site.lineno is not None else -1, b''.ljust(max(0, 4 - len(str(site.lineno)))), site.getsource(30), )