mirror of
https://github.com/certbot/certbot.git
synced 2026-05-28 04:34:11 -04:00
Replace pyparsing error that usually misdirects people with a more helpful message (#10265)
Addresses #10264, though I could not actually find a way to fix that particular issue. So, fixes #10264 is not actually accurate, but I would like github to link them.
This commit is contained in:
parent
16f858547f
commit
2da39317b2
2 changed files with 48 additions and 2 deletions
|
|
@ -233,8 +233,11 @@ class NginxParser:
|
|||
logger.warning("Could not read file: %s due to invalid "
|
||||
"character. Only UTF-8 encoding is "
|
||||
"supported.", filename)
|
||||
except pyparsing.ParseException as err:
|
||||
logger.warning("Could not parse file: %s due to %s", filename, err)
|
||||
except pyparsing.ParseException:
|
||||
logger.warning("Could not parse file: %s. This is usually due to a comment that "
|
||||
"certbot cannot parse, such as between a block's name and definition or "
|
||||
"within a string literal. Moving the comment to another location in the file "
|
||||
"or deleting it may resolve the issue.", filename)
|
||||
return trees
|
||||
|
||||
def _find_config_root(self) -> str:
|
||||
|
|
|
|||
|
|
@ -374,6 +374,49 @@ class TestRawNginxParser(unittest.TestCase):
|
|||
"""
|
||||
loads(test)
|
||||
|
||||
def test_location_comment_issue(self):
|
||||
# See discussion at https://github.com/certbot/certbot/issues/10264
|
||||
already_good = '''
|
||||
location = /resume
|
||||
# x
|
||||
{ rewrite .* /Files/Adam_Lein_resume.pdf redirect; }
|
||||
'''
|
||||
loads(already_good)
|
||||
already_good = '''
|
||||
location = /resume
|
||||
{ rewrite .* /Files/Adam_Lein_resume.pdf redirect; }
|
||||
# {
|
||||
'''
|
||||
loads(already_good)
|
||||
needs_fixing = '''
|
||||
location = /resume
|
||||
# {
|
||||
{ rewrite .* /Files/Adam_Lein_resume.pdf redirect; }
|
||||
'''
|
||||
with pytest.raises(ParseException):
|
||||
loads(needs_fixing) # fails
|
||||
needs_fixing = '''
|
||||
location = /resume
|
||||
# x{
|
||||
{ rewrite .* /Files/Adam_Lein_resume.pdf redirect; }
|
||||
'''
|
||||
with pytest.raises(ParseException):
|
||||
loads(needs_fixing) # fails
|
||||
needs_fixing = '''
|
||||
location = /resume
|
||||
#{
|
||||
{ rewrite .* /Files/Adam_Lein_resume.pdf redirect; }
|
||||
'''
|
||||
with pytest.raises(ParseException):
|
||||
loads(needs_fixing) # fails
|
||||
needs_fixing = '''
|
||||
location = /resume
|
||||
# {x
|
||||
{ rewrite .* /Files/Adam_Lein_resume.pdf redirect; }
|
||||
'''
|
||||
with pytest.raises(ParseException):
|
||||
loads(needs_fixing) # fails
|
||||
|
||||
|
||||
class TestUnspacedList(unittest.TestCase):
|
||||
"""Test the UnspacedList data structure"""
|
||||
|
|
|
|||
Loading…
Reference in a new issue