Skip to content

Commit 867a5e6

Browse files
committed
Revert change that made for ExpressionError #125
- Update the try/except clause instead of modifying the ExpressionError class. Signed-off-by: Chin Yeung Li <tli@nexb.com>
1 parent 348e0d1 commit 867a5e6

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/license_expression/__init__.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,7 @@
8787

8888

8989
class ExpressionError(Exception):
90-
def __init__(self, message, token_string=None):
91-
super().__init__(message)
92-
self.token_string = token_string
90+
pass
9391

9492

9593
class ExpressionParseError(ParseError, ExpressionError):
@@ -787,10 +785,14 @@ def validate(self, expression, strict=True, **kwargs):
787785
# Check `expression` type and syntax
788786
try:
789787
parsed_expression = self.parse(expression, strict=strict)
790-
except ExpressionError as e:
788+
except ExpressionParseError as e:
791789
expression_info.errors.append(str(e))
792790
expression_info.invalid_symbols.append(e.token_string)
793791
return expression_info
792+
except ExpressionError as e:
793+
expression_info.errors.append(str(e))
794+
expression_info.invalid_symbols.append(str(expression))
795+
return expression_info
794796

795797
# Check `expression` keys (validate)
796798
try:
@@ -1212,8 +1214,7 @@ def __init__(
12121214
raise ExpressionError(
12131215
"Invalid license key: the valid characters are: letters and "
12141216
"numbers, underscore, dot, colon or hyphen signs and "
1215-
f"spaces: {key!r}",
1216-
token_string=f"{key!r}",
1217+
f"spaces: {key!r}"
12171218
)
12181219

12191220
# normalize spaces
@@ -1222,8 +1223,7 @@ def __init__(
12221223
if key.lower() in KEYWORDS_STRINGS:
12231224
raise ExpressionError(
12241225
'Invalid license key: a key cannot be a reserved keyword: "or",'
1225-
f' "and" or "with": {key!r}',
1226-
token_string=f"{key!r}",
1226+
f' "and" or "with": {key!r}'
12271227
)
12281228

12291229
self.key = key

tests/test_license_expression.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2429,7 +2429,7 @@ def test_validation_invalid_license_key_chara(self):
24292429
assert result.errors == [
24302430
"Invalid license key: the valid characters are: letters and numbers, underscore, dot, colon or hyphen signs and spaces: 'cool,license'"
24312431
]
2432-
assert result.invalid_symbols == ["'cool,license'"]
2432+
assert result.invalid_symbols == ["cool,license"]
24332433

24342434
def test_validate_exception(self):
24352435
result = self.licensing.validate("GPL-2.0-or-later WITH WxWindows-exception-3.1")

0 commit comments

Comments
 (0)