mirror of
https://github.com/certbot/certbot.git
synced 2026-08-03 00:22:04 +02: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:
@@ -233,8 +233,11 @@ class NginxParser:
|
|||||||
logger.warning("Could not read file: %s due to invalid "
|
logger.warning("Could not read file: %s due to invalid "
|
||||||
"character. Only UTF-8 encoding is "
|
"character. Only UTF-8 encoding is "
|
||||||
"supported.", filename)
|
"supported.", filename)
|
||||||
except pyparsing.ParseException as err:
|
except pyparsing.ParseException:
|
||||||
logger.warning("Could not parse file: %s due to %s", filename, err)
|
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
|
return trees
|
||||||
|
|
||||||
def _find_config_root(self) -> str:
|
def _find_config_root(self) -> str:
|
||||||
|
|||||||
@@ -374,6 +374,49 @@ class TestRawNginxParser(unittest.TestCase):
|
|||||||
"""
|
"""
|
||||||
loads(test)
|
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):
|
class TestUnspacedList(unittest.TestCase):
|
||||||
"""Test the UnspacedList data structure"""
|
"""Test the UnspacedList data structure"""
|
||||||
|
|||||||
Reference in New Issue
Block a user