Bug 3214 - hgrc parse error caused by leading spaces are hard to spot
Summary: hgrc parse error caused by leading spaces are hard to spot
Status: RESOLVED FIXED
Alias: None
Product: Mercurial
Classification: Unclassified
Component: Mercurial (show other bugs)
Version: unspecified
Hardware: All All
: wish feature
Assignee: Bugzilla
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-01-23 04:07 UTC by Daniel Kullmann
Modified: 2020-11-10 00:00 UTC (History)
4 users (show)

See Also:
Python Version: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Kullmann 2012-01-23 04:07 UTC
When lines in hgrc start with spaces, you get a parse error. This happens
both for global hgrc and repo hgrc.

Example hgrc (note the leading space):

 [ui]
username=daniel
Comment 1 Benoit Boissinot 2012-01-23 04:18 UTC
I don't think that's a bug (and the message is quite detailed).
Comment 2 Daniel Kullmann 2012-01-23 04:25 UTC
This is the error message I get:

hg: parse error at .../.hg/hgrc:1:  [ui]

I don't think people will notice the space as being the problem.
Comment 3 Idan Kamara 2012-01-23 05:06 UTC
I guess we can wrap the erroneous line in ''...
Comment 4 Daniel Kullmann 2012-01-23 08:10 UTC
Why should a line starting with whitespace result in an error? I don't
understand that. I certainly was surprised when I realized that this really
was the source of the error; I almost didn't try to remove the whitespace
because I didn't expect this to be the problem.

And its really easy to fix: just add a l = l.lstrip() to the parse method.
Comment 5 Martin Geisler 2012-01-23 08:36 UTC
You can use leading white space for continuation, as in

[foo]
bar = this is
  a value with
  embedded newlines

That might help to explain why the whitespace is significant.
Comment 6 Daniel Kullmann 2012-01-23 08:46 UTC
OK, I understand that ;-)

Then the error message should be much better, like "Unexpected leading
whitespace", not just "parse error ..". There are many people unfamiliar
with the exact syntax of the rc file, after all.
Comment 7 Bugzilla 2012-05-12 09:27 UTC

--- Bug imported by bugzilla@serpentine.com 2012-05-12 09:27 EDT  ---

This bug was previously known as _bug_ 3213 at http://mercurial.selenic.com/bts/issue3213
Comment 8 Matt Mackall 2014-07-25 17:23 UTC
Bulk close: no activity for >2 years -> WONTFIX
Comment 9 Matt Mackall 2014-07-31 13:23 UTC
Bulk change recent WONTFIX -> new, more descriptive ARCHIVED state (sorry for the spam)
Comment 10 HG Bot 2014-08-26 06:15 UTC
Fixed by http://selenic.com/repo/hg/rev/b13b99d39a46
Razvan Cojocaru <razvan.cojocaru93@gmail.com>
config: highlight parse error caused by leading spaces (issue3214)

Added "unexpected leading whitespace" message to parse error
when .hgrc has a line that starts with whitespace.
Helps new users unfamiliar with syntax of rc file.

(please test the fix)
Comment 11 HG Bot 2020-11-02 01:55 UTC
Fixed by https://mercurial-scm.org/repo/hg/rev/0883413e09bc
Martin von Zweigbergk <martinvonz@google.com>
config: move message about leading spaces in config to config.py

When the config parser raises a ParseError, it uses the line that
failed to parse as the error message. It doesn't currently tell the
user anything about why it failed to parse. b13b99d39a46 (config:
highlight parse error caused by leading spaces (issue3214),
2014-03-16) added a checked based on the error *message* having
leading spaces. That has worked fine because only the config parser
uses the line itself as error message (I think the revset and fileset
parsers use more user-friendly proper messages). It still feels like a
hack. Let's make the config parser give a useful message about leading
whitespace instead. We should ideally follow up with more useful
messages for other parse errors in config files.

Differential Revision: https://phab.mercurial-scm.org/D9241

(please test the fix)
Comment 12 Bugzilla 2020-11-10 00:00 UTC
Bug was set to TESTING for 8 days, resolving