[fix] calculator plugin: crash when trying to evaluate non-math query (#4975)
Some checks are pending
Documentation / Release (push) Waiting to run
Integration / Python 3.11 (push) Waiting to run
Integration / Python 3.10 (push) Waiting to run
Integration / Python 3.12 (push) Waiting to run
Integration / Python 3.13 (push) Waiting to run
Integration / Python 3.9 (push) Waiting to run
Integration / Theme (push) Waiting to run

It's possible that `SyntaxError` or `TypeError` instances are thrown
when we can't evaluate a query, simply because it's not a math expression.
In this case, it should just be skipped, i.e. the calculator plugin doesn't
return any result instead of forwarding the exception.
This commit is contained in:
Bnyro 2025-07-04 21:32:54 +02:00 committed by GitHub
parent 01be2612ab
commit 5926d737e3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -170,8 +170,8 @@ def _eval_expr(expr):
root_expr = ast.parse(expr, mode='eval').body
return _eval(root_expr), isinstance(root_expr, ast.Compare)
except ZeroDivisionError:
# This is undefined
except (SyntaxError, TypeError, ZeroDivisionError):
# Expression that can't be evaluated (i.e. not a math expression)
return "", False