You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ponymail.apache.org by hu...@apache.org on 2021/06/06 10:38:20 UTC

[incubator-ponymail-foal] branch master updated: Add AssertionError catch, return a 500 if so

This is an automated email from the ASF dual-hosted git repository.

humbedooh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-ponymail-foal.git


The following commit(s) were added to refs/heads/master by this push:
     new 80e835b  Add AssertionError catch, return a 500 if so
80e835b is described below

commit 80e835b95dbf69863619934a08c8e3dbefd87a74
Author: Daniel Gruno <hu...@apache.org>
AuthorDate: Sun Jun 6 12:38:12 2021 +0200

    Add AssertionError catch, return a 500 if so
---
 server/endpoints/stats.py | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/server/endpoints/stats.py b/server/endpoints/stats.py
index 675f655..2f2c867 100644
--- a/server/endpoints/stats.py
+++ b/server/endpoints/stats.py
@@ -30,8 +30,11 @@ PYPONY_RE_PREFIX = re.compile(r"^([a-zA-Z]+:\s*)+")
 
 async def process(server: plugins.server.BaseServer, session: plugins.session.SessionObject, indata: dict,) -> dict:
 
-    query_defuzzed = plugins.defuzzer.defuzz(indata)
-    query_defuzzed_nodate = plugins.defuzzer.defuzz(indata, nodate=True)
+    try:
+        query_defuzzed = plugins.defuzzer.defuzz(indata)
+        query_defuzzed_nodate = plugins.defuzzer.defuzz(indata, nodate=True)
+    except AssertionError as e:  # If defuzzer encounters syntax errors, it will throw an AssertionError
+        return aiohttp.web.Response(headers={"content-type": "text/plain",}, status=500, text=str(e))
     results = await plugins.messages.query(
         session, query_defuzzed, query_limit=server.config.database.max_hits, shorten=True,
     )