From a6bb6ec5af1a050531755a4fd39cc169c56bcae1 Mon Sep 17 00:00:00 2001 From: Gregory Szorc Date: Fri, 17 Jul 2015 10:29:22 -0700 Subject: [PATCH] Bug 1178955 - Print line number for parse errors; r=smacleod It helps users debug problems. --HG-- extra : commitid : IU6Cw35FEiM extra : rebase_source : f6ab1ef356bb10b689f2fed034a9f2564ffe0fc3 extra : amend_source : ef52d60ca12796fcfe32392077a7606628a54d29 --- tools/mercurial/hgsetup/config.py | 10 ++++++---- tools/mercurial/hgsetup/wizard.py | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/tools/mercurial/hgsetup/config.py b/tools/mercurial/hgsetup/config.py index f0b5ed37db69..bf401b835ff0 100644 --- a/tools/mercurial/hgsetup/config.py +++ b/tools/mercurial/hgsetup/config.py @@ -31,7 +31,9 @@ def config_file(files): class ParseException(Exception): - pass + def __init__(self, line, msg): + self.line = line + super(Exception, self).__init__(msg) class MercurialConfig(object): @@ -47,12 +49,12 @@ class MercurialConfig(object): # error saying this. if os.path.exists(path): with codecs.open(path, 'r', encoding='utf-8') as f: - for line in f: + for i, line in enumerate(f): if line.startswith('%include'): - raise ParseException( + raise ParseException(i + 1, '%include directive is not supported by MercurialConfig') if line.startswith(';'): - raise ParseException( + raise ParseException(i + 1, 'semicolon (;) comments are not supported; ' 'use # instead') diff --git a/tools/mercurial/hgsetup/wizard.py b/tools/mercurial/hgsetup/wizard.py index 22794c08485e..e0edce79ddea 100644 --- a/tools/mercurial/hgsetup/wizard.py +++ b/tools/mercurial/hgsetup/wizard.py @@ -229,7 +229,7 @@ class MercurialSetupWizard(object): return 1 except ParseException as e: print('Error importing existing Mercurial config: %s\n' % config_path) - print(e.message) + print('Line %d: %s' % (e.line, e.message)) return 1