mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-10 20:05:49 +00:00
Bug 1334488 - [manifestparser] Improve error message when using an invalid comment character at the start of a manifest, r=jmaher
This refactors some of the error logic into a new IniParseError exception. In addition to checking for a 'name' property, we also check for a 'path' property. This is because some file-like objects coming out of the build system use a 'path' attribute instead of the standard 'name'. MozReview-Commit-ID: EXXl9gt1MQk --HG-- extra : rebase_source : a130824e6724fdef5cf0bd627b19db68ec5fe683
This commit is contained in:
parent
aaf554e02a
commit
3c4766fcab
@ -8,6 +8,18 @@ import sys
|
||||
__all__ = ['read_ini', 'combine_fields']
|
||||
|
||||
|
||||
class IniParseError(Exception):
|
||||
def __init__(self, fp, linenum, msg):
|
||||
if isinstance(fp, basestring):
|
||||
path = fp
|
||||
elif hasattr(fp, 'name'):
|
||||
path = fp.name
|
||||
else:
|
||||
path = getattr(fp, 'path', 'unknown')
|
||||
msg = "Error parsing manifest file '{}', line {}: {}".format(path, linenum, msg)
|
||||
super(IniParseError, self).__init__(msg)
|
||||
|
||||
|
||||
def read_ini(fp, variables=None, default='DEFAULT', defaults_only=False,
|
||||
comments=None, separators=None, strict=True, handle_defaults=True):
|
||||
"""
|
||||
@ -89,8 +101,8 @@ def read_ini(fp, variables=None, default='DEFAULT', defaults_only=False,
|
||||
|
||||
# if there aren't any sections yet, something bad happen
|
||||
if not section_names:
|
||||
raise Exception("Error parsing manifest file '%s', line %s: No sections found" %
|
||||
(getattr(fp, 'name', 'unknown'), linenum))
|
||||
raise IniParseError(fp, linenum, "Expected a comment or section, "
|
||||
"instead found '{}'".format(stripped))
|
||||
|
||||
# (key, value) pair
|
||||
for separator in separators:
|
||||
@ -114,8 +126,7 @@ def read_ini(fp, variables=None, default='DEFAULT', defaults_only=False,
|
||||
current_section[key] = value
|
||||
else:
|
||||
# something bad happened!
|
||||
raise Exception("Error parsing manifest file '%s', line %s" %
|
||||
(getattr(fp, 'name', 'unknown'), linenum))
|
||||
raise IniParseError(fp, linenum, "Unexpected line '{}'".format(stripped))
|
||||
|
||||
# server-root is a special os path declared relative to the manifest file.
|
||||
# inheritance demands we expand it as absolute
|
||||
|
Loading…
Reference in New Issue
Block a user