Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consistent use of ValueError when parsing settings. NFC #21245

Merged
merged 1 commit into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1457,7 +1457,8 @@ def parse_string_value(text):
first = text[0]
if first == "'" or first == '"':
text = text.rstrip()
assert text[-1] == text[0] and len(text) > 1, 'unclosed opened quoted string. expected final character to be "%s" and length to be greater than 1 in "%s"' % (text[0], text)
if text[-1] != text[0] or len(text) < 2:
raise ValueError(f'unclosed quoted string. expected final character to be "{text[0]}" and length to be greater than 1 in "{text[0]}"')
return text[1:-1]
return text

Expand All @@ -1469,15 +1470,15 @@ def parse_string_list_members(text):
while True:
current = values[index].lstrip() # Cannot safely rstrip for cases like: "HERE-> ,"
if not len(current):
exit_with_error('string array should not contain an empty value')
raise ValueError('empty value in string list')
first = current[0]
if not (first == "'" or first == '"'):
result.append(current.rstrip())
else:
start = index
while True: # Continue until closing quote found
if index >= len(values):
exit_with_error("unclosed quoted string. expected final character to be '%s' in '%s'" % (first, values[start]))
raise ValueError(f"unclosed quoted string. expected final character to be '{first}' in '{values[start]}'")
new = values[index].rstrip()
if new and new[-1] == first:
if start == index:
Expand All @@ -1498,7 +1499,7 @@ def parse_string_list(text):
text = text.rstrip()
if text and text[0] == '[':
if text[-1] != ']':
exit_with_error('unclosed opened string list. expected final character to be "]" in "%s"' % (text))
raise ValueError('unterminated string list. expected final character to be "]"')
text = text[1:-1]
if text.strip() == "":
return []
Expand Down
9 changes: 6 additions & 3 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -7663,19 +7663,22 @@ def test_dash_s_unclosed_quote(self):
# Unclosed quote
err = self.expect_fail([EMCC, test_file('hello_world.c'), '-s', "TEST_KEY='MISSING_QUOTE"])
self.assertNotContained('AssertionError', err) # Do not mention that it is an assertion error
self.assertContained('unclosed opened quoted string. expected final character to be "\'"', err)
self.assertContained('error: error parsing "-s" setting', err)
self.assertContained('unclosed quoted string. expected final character to be "\'"', err)

def test_dash_s_single_quote(self):
# Only one quote
err = self.expect_fail([EMCC, test_file('hello_world.c'), "-sTEST_KEY='"])
self.assertNotContained('AssertionError', err) # Do not mention that it is an assertion error
self.assertContained('unclosed opened quoted string.', err)
self.assertContained('error: error parsing "-s" setting', err)
self.assertContained('unclosed quoted string.', err)

def test_dash_s_unclosed_list(self):
# Unclosed list
err = self.expect_fail([EMCC, test_file('hello_world.cpp'), "-sTEST_KEY=[Value1, Value2"])
self.assertNotContained('AssertionError', err) # Do not mention that it is an assertion error
self.assertContained('unclosed opened string list. expected final character to be "]"', err)
self.assertContained('error: error parsing "-s" setting', err)
self.assertContained('unterminated string list. expected final character to be "]"', err)

def test_dash_s_valid_list(self):
err = self.expect_fail([EMCC, test_file('hello_world.cpp'), "-sTEST_KEY=[Value1, \"Value2\"]"])
Expand Down
Loading